use of org.apache.activemq.artemis.jms.client.ActiveMQJMSContext in project activemq-artemis by apache.
the class JmsProducerTest method multipleSendsUsingSetters.
@Test
public void multipleSendsUsingSetters() throws Exception {
server.createQueue(SimpleString.toSimpleString("q1"), RoutingType.ANYCAST, SimpleString.toSimpleString("q1"), null, true, false);
Queue q1 = context.createQueue("q1");
context.createProducer().setProperty("prop1", 1).setProperty("prop2", 2).send(q1, "Text1");
context.createProducer().setProperty("prop1", 3).setProperty("prop2", 4).send(q1, "Text2");
for (int i = 0; i < 100; i++) {
context.createProducer().send(q1, "Text" + i);
}
ActiveMQSession sessionUsed = (ActiveMQSession) (((ActiveMQJMSContext) context).getUsedSession());
ClientSessionImpl coreSession = (ClientSessionImpl) sessionUsed.getCoreSession();
// JMSConsumer is supposed to cache the producer, each call to createProducer is supposed to always return the same producer
assertEquals(1, coreSession.cloneProducers().size());
JMSConsumer consumer = context.createConsumer(q1);
TextMessage text = (TextMessage) consumer.receive(5000);
assertNotNull(text);
assertEquals("Text1", text.getText());
assertEquals(1, text.getIntProperty("prop1"));
assertEquals(2, text.getIntProperty("prop2"));
text = (TextMessage) consumer.receive(5000);
assertNotNull(text);
assertEquals("Text2", text.getText());
assertEquals(3, text.getIntProperty("prop1"));
assertEquals(4, text.getIntProperty("prop2"));
for (int i = 0; i < 100; i++) {
assertEquals("Text" + i, consumer.receiveBody(String.class, 1000));
}
consumer.close();
context.close();
}
Aggregations