conn.connect("0.0.0.0", 5672, "test", "guest", "guest");
}catch(Exception e){
e.printStackTrace();
}
Session ssn = conn.createSession(50000);
ssn.setClosedListener(new ClosedListener()
{
public void onClosed(ErrorCode errorCode, String reason, Throwable t)
{
System.out.println("ErrorCode : " + errorCode + " reason : " + reason);
}
});
ssn.queueDeclare("queue1", null, null);
ssn.exchangeBind("queue1", "amq.direct", "queue1",null);
ssn.sync();
ssn.messageSubscribe("queue1", "myDest", (short)0, (short)0,createAdapter(), null);
// queue
ssn.messageTransfer("amq.direct", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED,
new Header(new DeliveryProperties().setRoutingKey("queue1"),
new MessageProperties().setMessageId(UUID.randomUUID())),
ByteBuffer.wrap("this is the data".getBytes()));
//reject
ssn.messageTransfer("amq.direct", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED,
new Header(new DeliveryProperties().setRoutingKey("stocks")),
ByteBuffer.wrap("this should be rejected".getBytes()));
ssn.sync();
// topic subs
ssn.messageSubscribe("topic1", "myDest2", (short)0, (short)0,createAdapter(), null);
ssn.messageSubscribe("topic2", "myDest3", (short)0, (short)0,createAdapter(), null);
ssn.messageSubscribe("topic3", "myDest4", (short)0, (short)0,createAdapter(), null);
ssn.sync();
ssn.queueDeclare("topic1", null, null);
ssn.exchangeBind("topic1", "amq.topic", "stock.*",null);
ssn.queueDeclare("topic2", null, null);
ssn.exchangeBind("topic2", "amq.topic", "stock.us.*",null);
ssn.queueDeclare("topic3", null, null);
ssn.exchangeBind("topic3", "amq.topic", "stock.us.rh",null);
ssn.sync();
// topic
ssn.messageTransfer("amq.topic", MessageAcceptMode.NONE, MessageAcquireMode.PRE_ACQUIRED,
new Header(new DeliveryProperties().setRoutingKey("stock.us.ibm"),
new MessageProperties().setMessageId(UUID.randomUUID())),
ByteBuffer.wrap("Topic message".getBytes()));
}