use of org.springframework.jms.core.ProducerCallback in project rocketmq-externals by apache.
the class JmsConsumeIT method testConsume.
@Test
public void testConsume() throws Exception {
final Topic topic = (Topic) consumeContext.getBean("baseTopic");
JmsTestListener messageListener = (JmsTestListener) consumeContext.getBean("messageListener");
CountDownLatch countDownLatch = new CountDownLatch(1);
messageListener.setLatch(countDownLatch);
messageListener.setExpectd(30);
consumeContext.start();
for (int i = 0; i < 30; i++) {
jmsTemplate.execute(topic, new ProducerCallback() {
@Override
public Object doInJms(Session session, MessageProducer producer) throws JMSException {
JmsTextMessage message = (JmsTextMessage) session.createTextMessage("hello world,kafka, haha");
producer.send(topic, message);
Assert.assertNotNull(message.getJMSMessageID());
return message;
}
});
}
if (countDownLatch.await(30, TimeUnit.SECONDS)) {
Thread.sleep(2000);
}
Assert.assertEquals(30, messageListener.getConsumedNum());
consumeContext.close();
}
use of org.springframework.jms.core.ProducerCallback in project rocketmq-externals by apache.
the class JmsProduceIT method simpleSendTest.
@Test
public void simpleSendTest() throws Exception {
// Send text message
jmsTemplate.execute(destination, new ProducerCallback() {
@Override
public Object doInJms(Session session, MessageProducer producer) throws JMSException {
JmsTextMessage message = (JmsTextMessage) session.createTextMessage("hello world,kafka");
producer.send(destination, message);
Assert.assertNotNull(message.getJMSMessageID());
return message;
}
});
// Send object message
jmsTemplate.execute(destination, new ProducerCallback() {
@Override
public Object doInJms(Session session, MessageProducer producer) throws JMSException {
JmsObjectMessage message = (JmsObjectMessage) session.createObjectMessage(Lists.newArrayList(1, 2, 3));
producer.send(destination, message);
Assert.assertNotNull(message.getJMSMessageID());
return message;
}
});
// Send byte message
jmsTemplate.execute(destination, new ProducerCallback() {
@Override
public Object doInJms(Session session, MessageProducer producer) throws JMSException {
byte[] ts = "Von,Test".getBytes();
JmsBytesMessage message = (JmsBytesMessage) session.createBytesMessage();
message.writeBytes(ts);
producer.send(destination, message);
Assert.assertNotNull(message.getJMSMessageID());
return message;
}
});
}
Aggregations