Subscribing to location streams

We push a filtered GPS stream of all your drivers to a Apache Kafka cluster in real time. You can use this stream to analyze/visualize/store location data. This is a step-by-step guide to access this data.

[info] Request Access

Subscribing to location streams is in private beta. To get early access, write to us at help@hypertrack.io, and we would send you a username/password to connect to the Kafka cluster and the topic name on which your stream is published.

Verify the stream

Let us verify that your credentials are working by accessing the GPS stream on a python shell.

Pre-requisite

You need to be on Unix-like machine (typically Mac/EC2) and have python + pip install working on it.

Install kafka-python

Get Python client for Kafka & start the python shell.

$ pip install kafka-python --user
$ python

Get live stream

Run the following code in your Python shell. Plug in your own username, password and topic name that we provided you over email. You should start seeing GPS stream if any of your drivers are live with HyperTrack SDK.

>>> from kafka import KafkaConsumer
>>> consumer = KafkaConsumer('YOUR_TOPIC_NAME',
                             bootstrap_servers=['stream.hypertrack.io:9092'],
                             group_id='group-A',
                             sasl_plain_username='<YOUR_USERNAME>',
                             sasl_plain_password='<YOUR_PASSWORD>',
                             sasl_mechanism='PLAIN',
                             security_protocol='SASL_PLAINTEXT')
>>> for message in consumer:
        print ("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition,
                                              message.offset, message.key,
                                              message.value))

The message content (message.value) is of the following format:

{
 "recorded_at": "2017-01-09T11:16:31.747000+00:00",  # timestamp of when the GPS coordinates were recorded
 "driver_id": "bc5cc6c8-e478-45b7-8574-c4ffbd169c9f",
 "location_accuracy": 14.0,
 "location": {
              "type": "Point",
              "coordinates": [72.866626115472, 19.0786579483714]
             },
 "speed": 0.79,
 "activities": ["walking"],
 "bearing": 242.0,
 "altitude": -66.0,
 "activity_confidence": 92
}

Setup production consumer

  • Kafka clients are available for all popular programming languages (Java, Ruby, Python, PHP). For others, choose the appropriate one from here. Every language implementation might slightly differ but following are the common configuration options that you will have to provide to connect to our cluster.
Property Description Value
topic Name of the Topic where GPS stream of all your drivers is published. YOUR_TOPIC_NAME
bootstrap_servers List of kafka endpoints. stream.hypertrack.io:9092
security_protocol Type of Security Protocol SASL_PLAINTEXT
sasl_mechanism Type of Simple Authentication and Security Layer (SASL) PLAIN
sasl_plain_username Username to connect to Kafka cluster YOUR_USERNAME
sasl_plain_password Passowrd to connect to Kafka cluster YOUR_PASSWORD
group_id Group id of consumer. If you have a set of consumer processes all listening to the same Topic then they should share a common group_id. That way same message is not sent to multiple consumers. any string shared across all consumers
  • Here is a good description of all consumer configs for an example python client.

  • For production setup, we highly recommend reading through KafkaConsumer docs for guidance on consuming Kafka streams in fault tolerant way.

Was this helpful? Yes, thanks! Not really

results matching ""

    No results matching ""