Search in sources :

Example 1 with ActiveMQJMSContext

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();
}
Also used : ActiveMQJMSContext(org.apache.activemq.artemis.jms.client.ActiveMQJMSContext) JMSConsumer(javax.jms.JMSConsumer) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionImpl(org.apache.activemq.artemis.core.client.impl.ClientSessionImpl) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Aggregations

JMSConsumer (javax.jms.JMSConsumer)1 Queue (javax.jms.Queue)1 TextMessage (javax.jms.TextMessage)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ClientSessionImpl (org.apache.activemq.artemis.core.client.impl.ClientSessionImpl)1 ActiveMQJMSContext (org.apache.activemq.artemis.jms.client.ActiveMQJMSContext)1 ActiveMQSession (org.apache.activemq.artemis.jms.client.ActiveMQSession)1 Test (org.junit.Test)1