Testing the Vert.x kinesis module

I needed a simple way to test queueing a Kinesis message with the Vert.x Kinesis module. This Jython script will do it:

import vertx
from core.event_bus import EventBus
from org.vertx.java.core.json import JsonObject
from org.python.core.util import StringUtil

module = "com.zanox.vertx.mods~mod-kinesis~1.4.13"

def handler(_, x):
    print "Deployed kinesis module: %s" % x
    data = JsonObject()
    data.putBinary("payload", StringUtil.toBytes("this is a test"))
    send_message(data)


def send_message(msg, address="kinesis.verticle"):
    print "sending a message"
    EventBus.send(address, msg, reply_handler) 

def reply_handler(message):
    print "I received a reply %s" % message.body


vertx.deploy_module(module, vertx.config(), 1, handler)

Assuming the script is named test.py, run it by doing:

vertx run test.py -conf conf.json

See the module’s README for the conf.json format, should look something like this:

{
    "address": "kinesis.verticle",
    "streamName": "test-stream",
    "partitionKey": "partitionKey",
    "region": "us-east-1"
}

You’ll also need to create a stream first. You can use the AWS CLI for this:

aws kinesis create-stream --stream-name test-stream --shard-count 1
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s