use of org.fusesource.stomp.client.BlockingConnection in project camel by apache.
the class StompProducerTest method testProduce.
@Test
public void testProduce() throws Exception {
if (!canTest()) {
return;
}
context.addRoutes(createRouteBuilder());
context.start();
Stomp stomp = createStompClient();
final BlockingConnection subscribeConnection = stomp.connectBlocking();
StompFrame frame = new StompFrame(SUBSCRIBE);
frame.addHeader(DESTINATION, StompFrame.encodeHeader("/queue/test"));
frame.addHeader(ID, subscribeConnection.nextId());
StompFrame response = subscribeConnection.request(frame);
final CountDownLatch latch = new CountDownLatch(numberOfMessages);
Thread thread = new Thread(new Runnable() {
public void run() {
for (int i = 0; i < numberOfMessages; i++) {
try {
StompFrame frame = subscribeConnection.receive();
frame.contentAsString().startsWith("test message ");
latch.countDown();
} catch (Exception e) {
e.printStackTrace();
break;
}
}
}
});
thread.start();
Producer producer = context.getEndpoint("direct:foo").createProducer();
for (int i = 0; i < numberOfMessages; i++) {
Exchange exchange = producer.createExchange();
exchange.getIn().setBody(("test message " + i).getBytes("UTF-8"));
producer.process(exchange);
}
latch.await(20, TimeUnit.SECONDS);
assertTrue("Messages not consumed = " + latch.getCount(), latch.getCount() == 0);
}
use of org.fusesource.stomp.client.BlockingConnection in project camel by apache.
the class StompConsumerTest method testConsume.
@Test
public void testConsume() throws Exception {
if (!canTest()) {
return;
}
context.addRoutes(createRouteBuilder());
context.start();
Stomp stomp = createStompClient();
final BlockingConnection producerConnection = stomp.connectBlocking();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(numberOfMessages);
for (int i = 0; i < numberOfMessages; i++) {
StompFrame frame = new StompFrame(SEND);
frame.addHeader(DESTINATION, StompFrame.encodeHeader("/queue/test"));
frame.addHeader(MESSAGE_ID, StompFrame.encodeHeader("msg:" + i));
frame.content(utf8("Important Message " + i));
producerConnection.send(frame);
}
mock.await(5, TimeUnit.SECONDS);
mock.assertIsSatisfied();
}
use of org.fusesource.stomp.client.BlockingConnection in project camel by apache.
the class StompConsumerUriTest method testConsume.
@Test
public void testConsume() throws Exception {
if (!canTest()) {
return;
}
context.addRoutes(createRouteBuilder());
context.start();
Stomp stomp = createStompClient();
final BlockingConnection producerConnection = stomp.connectBlocking();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(numberOfMessages);
for (int i = 0; i < numberOfMessages; i++) {
StompFrame frame = new StompFrame(SEND);
frame.addHeader(DESTINATION, StompFrame.encodeHeader("/queue/test"));
frame.addHeader(MESSAGE_ID, StompFrame.encodeHeader("msg:" + i));
frame.content(utf8("Important Message " + i));
producerConnection.send(frame);
}
mock.await(5, TimeUnit.SECONDS);
mock.assertIsSatisfied();
}
Aggregations