|
| 1 | +# Geofancy-Java |
| 2 | + |
| 3 | +Geofancy is a (hopefully) simple [gRPC](http://grpc.io) service that implements a subset of [Tile38](http://tile38.com). |
| 4 | + |
| 5 | +This repository contains the Java/Kotlin implementation. |
| 6 | + |
| 7 | +There is also another repository ([geofancy-rs](https://github.com/MovingGauteng/geofancy-rs)), which contains the Rust implementation of the server. |
| 8 | + |
| 9 | +## Why Geofancy? |
| 10 | + |
| 11 | +Tile38 is a great program, that amongst others, allows one to set geofences between moving and static geospatial objects; with the ability to trigger webhooks when conditions are met. |
| 12 | + |
| 13 | +While we have tried out Tile38, we didn't want to implement all the logic that we wanted within some of our services, so we decided to create a separate service instead. |
| 14 | + |
| 15 | +Geofancy is a stand-alone microservice that connects with Tile38, and exposes a subset of its API via a gRPC service. |
| 16 | + |
| 17 | +### Implemented Methods |
| 18 | + |
| 19 | +You can view the `geofancy.proto` , which lists the RPCs that are supported. |
| 20 | + |
| 21 | +At the time of writing (imagine a blog post with no date having this line) ... The API is still unstable, and can evolve. |
| 22 | +We have |
| 23 | + |
| 24 | +```proto |
| 25 | +service GeofancyService { |
| 26 | + rpc CreateWebHook (GeoFence) returns (CommandResult) {} |
| 27 | + rpc DeleteWebHook (SearchString) returns (CommandResult) {} |
| 28 | + rpc SetDocument (Document) returns (CommandResult) {} |
| 29 | + rpc DeleteDocument (Document) returns (CommandResult) {} |
| 30 | + rpc DeleteCollection (Document) returns (CommandResult) {} |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +Notice that we return a very simple `CommandResult` message. Contributions are welcome, if anyone would like to return something more solid as a result. |
| 35 | + |
| 36 | +### Example |
| 37 | + |
| 38 | +We have included a `GeofancyClient` stub, which you can use to try out the API. |
| 39 | + |
| 40 | +```kotlin |
| 41 | + |
| 42 | +import za.co.movinggauteng.protos.geofancy.Coordinate |
| 43 | +import za.co.movinggauteng.protos.geofancy.GeoFence |
| 44 | +import za.co.movinggauteng.protos.geofancy.Point |
| 45 | + |
| 46 | +fun main(args: Array<String>) { |
| 47 | + val geofancyClient = GeofancyClient(dotenv["GRPC_SERVER_HOST"] ?: "localhost", (dotenv["GRPC_SERVER_PORT"] ?: "5003").toInt()) |
| 48 | + |
| 49 | + geofancyClient.getBlockingStub().createWebHook(GeoFence.newBuilder() |
| 50 | + .setId("the-id-that-will-get-triggered-by-a-webhook") |
| 51 | + .setEndpoint("http://localhost/webhook,grpc://localhost:9003") |
| 52 | + .setMatch("*") |
| 53 | + .setNearby(GeoFence.QueryNearby.newBuilder().setCollection("your-collection-name").build()) |
| 54 | + .addAllDetect(listOf(GeoFence.Detect.ENTER, GeoFence.Detect.INSIDE)) |
| 55 | + .addAllCommands(listOf(GeoFence.Commands.SET)) |
| 56 | + .setPoint(Point.newBuilder().setCoord(Coordinate.newBuilder().setLat(-26.1).setLng(28.12)).build()) |
| 57 | + .setDistance(200L) |
| 58 | + .build() |
| 59 | + ) |
| 60 | +} |
| 61 | +``` |
0 commit comments