Discovery Streams dynamically finds kafka topics and makes available corresponding channels on a public websocket.
Channels are named with the form of streaming:{dataset systemName}
(example: streaming:central_ohio_transit_authority__cota_stream
).
- Install websocat.
- Start websocat:
websocat wss://streams.smartcolumbusos.com/socket/websocket -H='User-Agent: websocat'
- Connect to a dataset:
{"topic": "streaming:central_ohio_transit_authority__cota_stream","event":"phx_join","payload":{},"ref":"1"}
- The following response indicates a successful connection:
{"event":"phx_reply","payload":{"response":{},"status":"ok"},"ref":"1","topic":"streaming:central_ohio_transit_authority__cota_stream"}
-
In the smartcitiesdata directory, install dependencies:
mix deps.get
-
In this directory, start Docker:
MIX_ENV=integration mix docker.start
-
Start the Phoenix server:
MIX_ENV=integration mix phx.server # ...or start interactively: MIX_ENV=integration iex -S mix phx.server
-
Install websocat.
-
Start Docker from Andi. Run Andi and Reaper locally.
-
In
discovery_streams > config > config.exs
, underconfig :discovery_streams
, settopic_prefix
to"raw-"
.- Make sure to change it back to
"transformed-"
when finished with local testing!
- Make sure to change it back to
-
Run Discovery Streams by starting the Phoenix server:
MIX_ENV=integration iex -S mix phx.server
-
Make a
PUT
request to the Andi API to add a dataset. -
Start websocat:
websocat ws://127.0.0.1:4001/socket/websocket -H='User-Agent: websocat'
-
Connect to your dataset:
{"topic": "streaming:central_ohio_transit_authority__cota_stream","event":"phx_join","payload":{},"ref":"1"}
- If using your own dataset, replace
central_ohio_transit_authority__cota_stream
with the system name of your dataset.
- If using your own dataset, replace
-
You should see the following success response:
{"event":"phx_reply","payload":{"response":{},"status":"ok"},"ref":"1","topic":"streaming:central_ohio_transit_authority__cota_stream"}
Every ten seconds (by default), you should see data events appear in the console.
A private dataset can be streamed by a client within the organization that owns the dataset. An API key can be provided in the phx_join
event by including the key-value pair "api_key":"<client API key>"
in the payload:
{"topic": "streaming:central_ohio_transit_authority__cota_stream","event":"phx_join","payload":{"api_key":"1234567890abcdefg"},"ref":"1"}
A filter can be provided in the phx_join
event by giving a filter key and value as the payload:
# Stream only vehicles with an id of 11409
websocat wss://streams.smartcolumbusos.com/socket/websocket -H='User-Agent: websocat'
{"topic": "streaming:central_ohio_transit_authority__cota_stream","event":"phx_join","payload":{"vehicle.vehicle.id":"11409"},"ref":"1"}
# Include both a filter and an API key
websocat wss://streams.smartcolumbusos.com/socket/websocket -H='User-Agent: websocat'
{"topic": "streaming:central_ohio_transit_authority__cota_stream","event":"phx_join","payload":{"api_key":"1234567890abcdefg","vehicle.vehicle.id":"11409"},"ref":"1"}
Variable | Description | Example |
---|---|---|
MIV_ENV | Environment for Mix build | dev , test , integration , or prod |
KAFKA_BROKERS | comma delimited list of kafka brokers | kafka1.com:9092,kafka2.com:9092 |
SECRET_KEY_BASE | Pheonix uses this to verify cookies. Generate with mix phx.gen.secret or pass in your own |
- Run
mix test
to run the tests a single time - Run
mix test.watch
to re-run the tests when a file changes - Run
mix test.watch --stale
to only rerun the tests for modules that have changes - Run
mix test.integration
to run the integration tests