properties.put("request.required.acks", "1");
ProducerConfig config = new ProducerConfig(properties);
Producer<String, byte[]> producer = new Producer<String, byte[]>(config);
TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
for (int i = 0; i < mNumMessages; ++i) {
TestMessage testMessage = new TestMessage(System.currentTimeMillis() * 1000000L + i,
"some_value_" + i);
if (i % 2 == 0) {
testMessage.setEnumField(TestEnum.SOME_VALUE);
} else {
testMessage.setEnumField(TestEnum.SOME_OTHER_VALUE);
}
byte[] bytes;
try {
bytes = serializer.serialize(testMessage);
} catch(TException e) {
throw new RuntimeException("Failed to serialize message " + testMessage, e);
}
KeyedMessage<String, byte[]> data = new KeyedMessage<String, byte[]>(
mTopic, Integer.toString(i), bytes);