This example shows you how to configure HornetQ to use the Twitter Connector Service.
HornetQ supports 2 types of Twitter connector, incoming and outgoing. Incoming connector consumes from twitter and forwards to a configurable address. Outgoing connector consumes from a configurable address and forwards to twitter.
In this example, incoming connector and outgoing connector is related to same twitter account. So if you send a message to an outgoing address, outgoing connector forwards it to twitter, and then incoming connector consumes it and forwards to incoming address.
To run the server, simply type mvn-Dtwitter.consumerKey=consumer -Dtwitter.consumerSecret=secret -Dtwitter.accessToken=token -Dtwitter.accessTokenSecret=secret verify
from this directory but replacing the system properties with those of the twitter account you want to use. Then run the example
by using the command mvn -Pexample package
csf = HornetQClient.createClientSessionFactory(new TransportConfiguration(NettyConnectorFactory.class.getName()));
session = csf.createSession(true,true);
ClientProducer cp = session.createProducer(OUTGOING_QUEUE);
ClientConsumer cc = session.createConsumer(INCOMING_QUEUE);
ClientMessage cm = session.createMessage(org.apache.activemq.api.core.Message.TEXT_TYPE,true);
String testMessage = System.currentTimeMillis() + ": twitter connector test example";
cm.getBodyBuffer().writeString(testMessage);
cp.send(cm);
session.start();
ClientMessage received = cc.receive(70 * 1000);
received.acknowledge();
String receivedText = received.getBodyBuffer().readString();
finally
block.
finally
{
if(session != null)
{
session.close();
}
if(csf != null)
{
csf.close();
}
}