Java Code Examples for javax.jms.TextMessage#setJMSType()

The following examples show how to use javax.jms.TextMessage#setJMSType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsTypeHeaderInboundEndpointTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Send a message to testInboundQueue queue
 *
 * @throws Exception
 */
private void sendMessage() throws Exception {
    InitialContext initialContext = JmsClientHelper.getActiveMqInitialContext();
    QueueConnectionFactory connectionFactory
            = (QueueConnectionFactory) initialContext.lookup(JmsClientHelper.QUEUE_CONNECTION_FACTORY);
    QueueConnection queueConnection = connectionFactory.createQueueConnection();
    QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
    QueueSender sender = queueSession.createSender(queueSession.createQueue(QUEUE_NAME));

    String message = "<?xml version='1.0' encoding='UTF-8'?>" +
            "    <ser:getQuote xmlns:ser=\"http://services.samples\" xmlns:xsd=\"http://services.samples/xsd\"> " +
            "      <ser:request>" +
            "        <xsd:symbol>IBM</xsd:symbol>" +
            "      </ser:request>" +
            "    </ser:getQuote>";
    try {
        TextMessage jmsMessage = queueSession.createTextMessage(message);
        jmsMessage.setJMSType("incorrecttype");
        sender.send(jmsMessage);
    } finally {
        queueConnection.close();
    }
}
 
Example 2
Source File: SelectorTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Test the message selector using the filter example provided by the JMS specifications.
 * <br />
 * <ul>
 * <li><code>"JMSType = 'car' AND color = 'blue' AND weight > 2500"</code></li>
 * </ul>
 */
@Test
public void testSelectorExampleFromSpecs() throws Exception {
   if (receiver != null) {
      receiver.close();
   }
   receiver = receiverSession.createReceiver(receiverQueue, "JMSType = 'car' AND color = 'blue' AND weight > 2500");

   TextMessage dummyMessage = senderSession.createTextMessage();
   dummyMessage.setJMSType("car");
   dummyMessage.setStringProperty("color", "red");
   dummyMessage.setLongProperty("weight", 3000);
   dummyMessage.setText("testSelectorExampleFromSpecs:1");
   sender.send(dummyMessage);

   TextMessage message = senderSession.createTextMessage();
   message.setJMSType("car");
   message.setStringProperty("color", "blue");
   message.setLongProperty("weight", 3000);
   message.setText("testSelectorExampleFromSpecs:2");
   sender.send(message);

   TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
   Assert.assertEquals("testSelectorExampleFromSpecs:2", msg.getText());
}
 
Example 3
Source File: JmsDurableTopicSendReceiveTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Test if all the messages sent are being received.
 *
 * @throws Exception
 */
@Test
public void testSendWhileClosed() throws Exception {
   connection2 = factory.createConnection();
   connection2.setClientID("test");
   connection2.start();
   session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
   producer2 = session2.createProducer(null);
   producer2.setDeliveryMode(deliveryMode);
   producerDestination2 = this.createDestination2(session2, ActiveMQDestination.TOPIC_TYPE);
   Thread.sleep(1000);

   consumeSession2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
   consumerDestination2 = this.createDestination2(session2, ActiveMQDestination.TOPIC_TYPE);
   consumer2 = consumeSession2.createDurableSubscriber((Topic) consumerDestination2, getName());
   Thread.sleep(1000);
   consumer2.close();
   TextMessage message = session2.createTextMessage("test");
   message.setStringProperty("test", "test");
   message.setJMSType("test");
   producer2.send(producerDestination2, message);
   consumer2 = consumeSession2.createDurableSubscriber((Topic) consumerDestination2, getName());
   Message msg = consumer2.receive(1000);
   assertNotNull(msg);
   assertEquals(((TextMessage) msg).getText(), "test");
   assertEquals(msg.getJMSType(), "test");
   assertEquals(msg.getStringProperty("test"), "test");
   connection2.stop();
   connection2.close();
}
 
Example 4
Source File: JMSMessageConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void doTestSelectorsWithJMSType(boolean topic) throws Exception {
   final Connection connection = createConnection();
   final String type = "myJMSType";

   try {
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination destination = null;
      if (topic) {
         destination = session.createTopic(getTopicName());
      } else {
         destination = session.createQueue(getQueueName());
      }

      MessageProducer producer = session.createProducer(destination);
      MessageConsumer consumer = session.createConsumer(destination, "JMSType = '" + type + "'");

      TextMessage message1 = session.createTextMessage();
      message1.setText("text");
      producer.send(message1, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);

      TextMessage message2 = session.createTextMessage();
      message2.setJMSType(type);
      message2.setText("text + type");
      producer.send(message2, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);

      connection.start();

      Message msg = consumer.receive(2000);
      assertNotNull(msg);
      assertTrue(msg instanceof TextMessage);
      assertEquals("Unexpected JMSType value", type, msg.getJMSType());
      assertEquals("Unexpected message content", "text + type", ((TextMessage) msg).getText());
   } finally {
      connection.close();
   }
}
 
Example 5
Source File: JmsDurableTopicSendReceiveTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Test if all the messages sent are being received.
 *
 * @throws Exception
 */
public void testSendWhileClosed() throws Exception {
   connection2 = createConnection();
   connection2.setClientID("test");
   connection2.start();
   session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
   producer2 = session2.createProducer(null);
   producer2.setDeliveryMode(deliveryMode);
   producerDestination2 = session2.createTopic(getProducerSubject() + "2");
   Thread.sleep(1000);

   consumeSession2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
   consumerDestination2 = session2.createTopic(getConsumerSubject() + "2");
   consumer2 = consumeSession2.createDurableSubscriber((Topic) consumerDestination2, getName());
   Thread.sleep(1000);
   consumer2.close();
   TextMessage message = session2.createTextMessage("test");
   message.setStringProperty("test", "test");
   message.setJMSType("test");
   producer2.send(producerDestination2, message);
   LOG.info("Creating durable consumer");
   consumer2 = consumeSession2.createDurableSubscriber((Topic) consumerDestination2, getName());
   Message msg = consumer2.receive(1000);
   assertNotNull(msg);
   assertEquals(((TextMessage) msg).getText(), "test");
   assertEquals(msg.getJMSType(), "test");
   assertEquals(msg.getStringProperty("test"), "test");
   connection2.stop();
   connection2.close();
}
 
Example 6
Source File: MessageGroupNewConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public Message generateMessage(Session session, String groupId, int seq) throws JMSException {
   TextMessage m = session.createTextMessage();
   m.setJMSType("TEST_MESSAGE");
   m.setStringProperty("JMSXGroupID", groupId);
   m.setIntProperty("JMSXGroupSeq", seq);
   m.setText("<?xml?><testMessage/>");
   return m;
}
 
Example 7
Source File: DiscriminatingConsumerLoadTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
   try {
      final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      final Queue queue = session.createQueue("test");

      // wait for 10 seconds to allow consumer.receive to be run
      // first
      Thread.sleep(10000);
      MessageProducer producer = session.createProducer(queue);

      while (!stop && (counterSent < testSize)) {
         // first send a message intended to be consumed ....
         TextMessage message = session.createTextMessage("*** Ill ....... Ini ***"); // alma mater ...
         message.setJMSType(JMSTYPE_EATME);
         // LOG.info("sending .... JMSType = " + message.getJMSType());
         producer.send(message, DeliveryMode.NON_PERSISTENT, 0, 1800000);

         counterSent++;

         // now send a message intended to be consumed by some other consumer in the the future
         // ... we expect these messages to accrue in the queue
         message = session.createTextMessage("*** Ill ....... Ini ***"); // alma mater ...
         message.setJMSType(JMSTYPE_IGNOREME);
         // LOG.info("sending .... JMSType = " + message.getJMSType());
         producer.send(message, DeliveryMode.NON_PERSISTENT, 0, 1800000);

         counterSent++;
      }

      session.close();

   } catch (Exception e) {
      e.printStackTrace();
   }
   LOG.info("producer thread complete ... " + counterSent + " messages sent to the queue");
}
 
Example 8
Source File: MessageGroupCloseTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public Message generateMessage(Session session, String groupId, int seq) throws JMSException {
   TextMessage m = session.createTextMessage();
   m.setJMSType("TEST_MESSAGE");
   m.setStringProperty("JMSXGroupID", groupId);
   m.setIntProperty("JMSXGroupSeq", seq);
   m.setText("<?xml?><testMessage/>");
   return m;
}
 
Example 9
Source File: BaseTest.java    From a with Apache License 2.0 5 votes vote down vote up
private TextMessage createTextMessage(String testCorrId, String stringPropertyValue, String utfText, Queue replyQueue) throws JMSException {
    final TextMessage tm1 = session.createTextMessage(utfText);
    tm1.setStringProperty("myStringProperty", stringPropertyValue);
    tm1.setIntProperty("myIntProperty", 42);
    tm1.setDoubleProperty("myDoubleProperty", Math.PI);
    tm1.setJMSType("myJmsType");
    tm1.setJMSCorrelationID(testCorrId);
    tm1.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
    tm1.setJMSPriority(2);
    tm1.setJMSReplyTo(replyQueue);
    return tm1;
}
 
Example 10
Source File: JmsMessageConsumerTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout=45000)
public void testSelectorsWithJMSType() throws Exception {
    connection = createAmqpConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue(name.getMethodName());
    MessageProducer producer = session.createProducer(queue);

    TextMessage message = session.createTextMessage();
    message.setText("text");
    producer.send(message, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);

    TextMessage message2 = session.createTextMessage();
    String type = "myJMSType";
    message2.setJMSType(type);
    message2.setText("text + type");
    producer.send(message2, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);

    producer.close();

    final QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
    assertTrue("Queue did not get all expected messages", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisfied() throws Exception {
            return proxy.getQueueSize() == 2;
        }
    }));

    MessageConsumer consumer = session.createConsumer(queue, "JMSType = '" + type + "'");
    Message msg = consumer.receive(5000);
    assertNotNull("No message was recieved", msg);
    assertTrue(msg instanceof TextMessage);
    assertEquals("Unexpected JMSType value", type, msg.getJMSType());
    assertEquals("Unexpected message content", "text + type", ((TextMessage) msg).getText());
}
 
Example 11
Source File: JmsTopicSelectorTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void sendMessages() throws Exception {
   TextMessage message = session.createTextMessage("1");
   message.setIntProperty("id", 1);
   message.setJMSType("a");
   message.setStringProperty("stringProperty", "a");
   message.setLongProperty("longProperty", 1);
   message.setBooleanProperty("booleanProperty", true);
   producer.send(message);

   message = session.createTextMessage("2");
   message.setIntProperty("id", 2);
   message.setJMSType("a");
   message.setStringProperty("stringProperty", "a");
   message.setLongProperty("longProperty", 1);
   message.setBooleanProperty("booleanProperty", false);
   producer.send(message);

   message = session.createTextMessage("3");
   message.setIntProperty("id", 3);
   message.setJMSType("a");
   message.setStringProperty("stringProperty", "a");
   message.setLongProperty("longProperty", 1);
   message.setBooleanProperty("booleanProperty", true);
   producer.send(message);

   message = session.createTextMessage("4");
   message.setIntProperty("id", 4);
   message.setJMSType("b");
   message.setStringProperty("stringProperty", "b");
   message.setLongProperty("longProperty", 2);
   message.setBooleanProperty("booleanProperty", false);
   producer.send(message);

   message = session.createTextMessage("5");
   message.setIntProperty("id", 5);
   message.setJMSType("c");
   message.setStringProperty("stringProperty", "c");
   message.setLongProperty("longProperty", 3);
   message.setBooleanProperty("booleanProperty", true);
   producer.send(message);
}
 
Example 12
Source File: JmsTopicSelectorTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void sendMessages() throws Exception {
   TextMessage message = session.createTextMessage("1");
   message.setIntProperty("id", 1);
   message.setJMSType("a");
   message.setStringProperty("stringProperty", "a");
   message.setLongProperty("longProperty", 1);
   message.setBooleanProperty("booleanProperty", true);
   producer.send(message);

   message = session.createTextMessage("2");
   message.setIntProperty("id", 2);
   message.setJMSType("a");
   message.setStringProperty("stringProperty", "a");
   message.setLongProperty("longProperty", 1);
   message.setBooleanProperty("booleanProperty", false);
   producer.send(message);

   message = session.createTextMessage("3");
   message.setIntProperty("id", 3);
   message.setJMSType("a");
   message.setStringProperty("stringProperty", "a");
   message.setLongProperty("longProperty", 1);
   message.setBooleanProperty("booleanProperty", true);
   producer.send(message);

   message = session.createTextMessage("4");
   message.setIntProperty("id", 4);
   message.setJMSType("b");
   message.setStringProperty("stringProperty", "b");
   message.setLongProperty("longProperty", 2);
   message.setBooleanProperty("booleanProperty", false);
   producer.send(message);

   message = session.createTextMessage("5");
   message.setIntProperty("id", 5);
   message.setJMSType("c");
   message.setStringProperty("stringProperty", "c");
   message.setLongProperty("longProperty", 3);
   message.setBooleanProperty("booleanProperty", true);
   producer.send(message);
}
 
Example 13
Source File: SelectorTest.java    From activemq-artemis with Apache License 2.0 3 votes vote down vote up
@Test
public void testJMSTypeOnSelector() throws Exception {
   Connection conn = null;

   try {
      conn = getConnectionFactory().createConnection();
      conn.start();

      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageProducer prod = session.createProducer(queue1);

      TextMessage msg1 = session.createTextMessage("msg1");
      msg1.setJMSType("type1");
      prod.send(msg1);

      TextMessage msg2 = session.createTextMessage("msg2");
      msg2.setJMSType("type2");
      prod.send(msg2);

      String selector = "JMSType = 'type2'";

      MessageConsumer cons = session.createConsumer(queue1, selector);

      conn.start();

      TextMessage rec = (TextMessage) cons.receive(10000);

      assertNotNull(rec);

      Assert.assertEquals("msg2", rec.getText());

      assertNull(cons.receiveNoWait());

   } finally {
      if (conn != null) {
         conn.close();
      }
   }
}