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

The following examples show how to use javax.jms.TextMessage#setIntProperty() . 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: JmsTopicSendSameMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public void testSendReceive() throws Exception {
   messages.clear();

   TextMessage message = session.createTextMessage();

   for (int i = 0; i < data.length; i++) {
      message.setText(data[i]);
      message.setStringProperty("stringProperty", data[i]);
      message.setIntProperty("intProperty", i);

      if (verbose) {
         LOG.info("About to send a message: " + message + " with text: " + data[i]);
      }

      producer.send(producerDestination, message);
   }

   assertMessagesAreReceived();
}
 
Example 2
Source File: AMQ1925Test.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void sendMessagesToQueue() throws Exception {
   Connection connection = cf.createConnection();
   Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
   MessageProducer producer = session.createProducer(session.createQueue(QUEUE_NAME));

   producer.setDeliveryMode(DeliveryMode.PERSISTENT);
   for (int i = 0; i < MESSAGE_COUNT; i++) {
      TextMessage message = session.createTextMessage("Test message " + i);
      message.setIntProperty(PROPERTY_MSG_NUMBER, i);
      producer.send(message);
   }
   session.commit();

   producer.close();
   session.close();
   connection.close();

   assertQueueLength(MESSAGE_COUNT);
}
 
Example 3
Source File: SelectorTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Test the BETWEEN condition in message selector.
 * <br />
 * <ul>
 * <li>"age BETWEEN 15 and 19" is <code>true</code> for 17 and <code>false</code> for 20</li>
 * </ul>
 */
@Test
public void testBetween() throws Exception {
   if (receiver != null) {
      receiver.close();
   }
   receiver = receiverSession.createReceiver(receiverQueue, "age BETWEEN 15 and 19");

   TextMessage dummyMessage = senderSession.createTextMessage();
   dummyMessage.setIntProperty("age", 20);
   dummyMessage.setText("testBetween:1");
   sender.send(dummyMessage);

   TextMessage message = senderSession.createTextMessage();
   message.setIntProperty("age", 17);
   message.setText("testBetween:2");
   sender.send(message);

   TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
   Assert.assertTrue("Message not received", msg != null);
   Assert.assertTrue("Message of another test: " + msg.getText(), msg.getText().startsWith("testBetween"));
   Assert.assertEquals("testBetween:2", msg.getText());
}
 
Example 4
Source File: ActiveMqFacade.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Override
public TextMessage createTextMessage(String messageText) throws JMSException {
    TextMessage message = session.createTextMessage(messageText);
    message.setStringProperty("test_string_property", "test123");
    message.setIntProperty("test_int_property", 123);
    message.setStringProperty("passwd", "secret");
    message.setStringProperty("null_property", null);
    return message;
}
 
Example 5
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 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: JMSOrderTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void sendMessages(Connection connection, Destination destination, int count) throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer p = session.createProducer(destination);

   for (int i = 1; i <= count; i++) {
      TextMessage message = session.createTextMessage();
      message.setText("TextMessage: " + i);
      message.setIntProperty("nr", i);
      p.send(message);
   }

   session.close();

}
 
Example 8
Source File: ConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testAutoDeleteAutoCreatedAddressAndQueue() throws Throwable {
   if (!isNetty()) {
      // no need to run the test, there's no AMQP support
      return;
   }

   assertNull(server.getAddressInfo(SimpleString.toSimpleString("queue")));

   ConnectionFactory factorySend = createFactory(2);
   Connection connection = factorySend.createConnection();

   try {
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      javax.jms.Queue queue = session.createQueue("queue");
      MessageProducer producer = session.createProducer(queue);
      producer.setDeliveryMode(DeliveryMode.PERSISTENT);

      TextMessage msg = session.createTextMessage("hello");
      msg.setIntProperty("mycount", 0);
      producer.send(msg);

      connection.start();
      MessageConsumer consumer = session.createConsumer(queue);
      assertNotNull(consumer.receive(1000));
   } finally {
      connection.close();
   }

   Wait.assertTrue(() -> server.getAddressInfo(SimpleString.toSimpleString("queue")) == null);
   Wait.assertTrue(() -> server.locateQueue(SimpleString.toSimpleString("queue")) == null);
   Wait.assertEquals(0, server::getTotalMessageCount);
}
 
Example 9
Source File: RollbacksWhileConsumingLargeQueueTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected MessageCreator createMessageCreator(final int i) {
   return new MessageCreator() {
      @Override
      public Message createMessage(Session session) throws JMSException {
         TextMessage answer = session.createTextMessage("Message: " + i);
         answer.setIntProperty("Counter", i);
         return answer;
      }
   };
}
 
Example 10
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 11
Source File: PropertyFilterTest.java    From brave with Apache License 2.0 5 votes vote down vote up
static void setAllPropertyTypes(TextMessage message) throws JMSException {
  message.setBooleanProperty("boolean", true);
  message.setByteProperty("byte", Byte.MAX_VALUE);
  message.setDoubleProperty("double", Double.MIN_VALUE);
  message.setFloatProperty("float", Float.MIN_VALUE);
  message.setIntProperty("int", Integer.MIN_VALUE);
  message.setLongProperty("long", Long.MIN_VALUE);
  message.setObjectProperty("object", Collections.emptyMap());
  message.setShortProperty("short", Short.MIN_VALUE);
  message.setStringProperty("string", "string");
}
 
Example 12
Source File: JmsSourceTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithString() throws JMSException {
    WeldContainer container = prepare();

    RawMessageConsumerBean bean = container.select(RawMessageConsumerBean.class).get();
    assertThat(bean.messages()).isEmpty();

    Queue q = jms.createQueue("queue-one");
    JMSProducer producer = jms.createProducer();
    TextMessage message = jms.createTextMessage("hello");
    message.setStringProperty("string", "value");
    message.setBooleanProperty("bool", true);
    message.setLongProperty("long", 100L);
    message.setByteProperty("byte", (byte) 5);
    message.setFloatProperty("float", 5.5f);
    message.setDoubleProperty("double", 10.3);
    message.setIntProperty("int", 23);
    message.setObjectProperty("object", "yop");
    message.setShortProperty("short", (short) 3);
    producer.send(q, message);

    await().until(() -> bean.messages().size() == 1);
    IncomingJmsMessage<?> incomingJmsMessage = bean.messages().get(0);
    IncomingJmsMessageMetadata metadata = incomingJmsMessage.getMetadata(IncomingJmsMessageMetadata.class)
            .orElseThrow(() -> new AssertionError("Metadata expected"));
    assertThat(incomingJmsMessage.getPayload()).isEqualTo("hello");
    assertThat(metadata.getBody(String.class)).isEqualTo("hello");
    assertThat(metadata.propertyExists("string")).isTrue();
    assertThat(metadata.propertyExists("missing")).isFalse();
    assertThat(metadata.getStringProperty("string")).isEqualTo("value");
    assertThat(metadata.getBooleanProperty("bool")).isTrue();
    assertThat(metadata.getLongProperty("long")).isEqualTo(100L);
    assertThat(metadata.getByteProperty("byte")).isEqualTo((byte) 5);
    assertThat(metadata.getFloatProperty("float")).isEqualTo(5.5f);
    assertThat(metadata.getDoubleProperty("double")).isEqualTo(10.3);
    assertThat(metadata.getIntProperty("int")).isEqualTo(23);
    assertThat(metadata.getObjectProperty("object")).isInstanceOf(String.class);
    assertThat(((String) message.getObjectProperty("object"))).isEqualTo("yop");
    assertThat(message.getShortProperty("short")).isEqualTo((short) 3);
}
 
Example 13
Source File: ActiveMqArtemisFacade.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Override
public TextMessage createTextMessage(String messageText) throws JMSException {
    TextMessage message = context.createTextMessage(messageText);
    message.setStringProperty("test_string_property", "test123");
    message.setIntProperty("test_int_property", 123);
    message.setStringProperty("passwd", "secret");
    message.setStringProperty("null_property", null);
    return message;
}
 
Example 14
Source File: RequestReplyToTopicViaThreeNetworkHopsTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void testMessages(Session sess,
                         MessageProducer req_prod,
                         Destination resp_dest,
                         int num_msg) throws Exception {
   MessageConsumer resp_cons;
   TextMessage msg;
   MessageClient cons_client;
   int cur;
   int tot_expected;

   resp_cons = sess.createConsumer(resp_dest);

   cons_client = new MessageClient(resp_cons, num_msg);
   cons_client.start();

   cur = 0;
   while ((cur < num_msg) && (!fatalTestError)) {
      msg = sess.createTextMessage("MSG AAAA " + cur);
      msg.setIntProperty("SEQ", 100 + cur);
      msg.setStringProperty("TEST", "TOPO");
      msg.setJMSReplyTo(resp_dest);

      if (cur == (num_msg - 1))
         msg.setBooleanProperty("end-of-response", true);

      sendWithRetryOnDeletedDest(req_prod, msg);
      LOG.debug("Sent:" + msg);

      cur++;
   }

   //
   // Give the consumer some time to receive the response.
   //
   cons_client.waitShutdown(5000);

   //
   // Now shutdown the consumer if it's still running.
   //
   if (cons_client.shutdown())
      LOG.debug("Consumer client shutdown complete");
   else
      LOG.debug("Consumer client shutdown incomplete!!!");

   //
   // Check that the correct number of messages was received.
   //
   tot_expected = num_msg * (echoResponseFill + 1);

   if (cons_client.getNumMsgReceived() == tot_expected) {
      LOG.debug("Have " + tot_expected + " messages, as-expected");
   } else {
      testError = true;

      if (cons_client.getNumMsgReceived() == 0)
         fatalTestError = true;

      LOG.error("Have " + cons_client.getNumMsgReceived() + " messages; expected " + tot_expected + " on destination " + resp_dest);
   }

   resp_cons.close();
}
 
Example 15
Source File: JmsConsumerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testBrowserAndConsumerSimultaneous() throws Exception {
   ((ActiveMQConnectionFactory) cf).setConsumerWindowSize(0);
   conn = cf.createConnection();

   Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME);
   MessageProducer producer = session.createProducer(jBossQueue);

   QueueBrowser browser = session.createBrowser(jBossQueue);
   Enumeration enumMessages = browser.getEnumeration();

   MessageConsumer consumer = session.createConsumer(jBossQueue);
   int noOfMessages = 10;
   for (int i = 0; i < noOfMessages; i++) {
      TextMessage textMessage = session.createTextMessage("m" + i);
      textMessage.setIntProperty("i", i);
      producer.send(textMessage);
   }

   conn.start();
   for (int i = 0; i < noOfMessages; i++) {
      TextMessage msg = (TextMessage) enumMessages.nextElement();
      Assert.assertNotNull(msg);
      Assert.assertEquals(i, msg.getIntProperty("i"));

      conn.start();
      TextMessage recvMessage = (TextMessage) consumer.receiveNoWait();
      Assert.assertNotNull(recvMessage);
      conn.stop();
      Assert.assertEquals(i, msg.getIntProperty("i"));
   }

   Assert.assertNull(consumer.receiveNoWait());
   Assert.assertFalse(enumMessages.hasMoreElements());

   conn.close();

   // Asserting delivering count is zero is bogus since messages might still be being delivered and expired at this
   // point
   // which can cause delivering count to flip to 1
}
 
Example 16
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 17
Source File: JMSMessageConsumerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private void doTestSelectorsWithJMSXGroupID(boolean topic) throws Exception {

      Connection connection = createConnection();

      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, "JMSXGroupID = '1'");

         TextMessage message = session.createTextMessage();
         message.setText("group 1 - 1");
         message.setStringProperty("JMSXGroupID", "1");
         message.setIntProperty("JMSXGroupSeq", 1);
         producer.send(message);

         message = session.createTextMessage();
         message.setText("group 2");
         message.setStringProperty("JMSXGroupID", "2");
         producer.send(message);

         message = session.createTextMessage();
         message.setText("group 1 - 2");
         message.setStringProperty("JMSXGroupID", "1");
         message.setIntProperty("JMSXGroupSeq", -1);
         producer.send(message);

         connection.start();

         Message msg = consumer.receive(2000);
         assertNotNull(msg);
         assertTrue(msg instanceof TextMessage);
         assertEquals("group 1 - 1", ((TextMessage) msg).getText());
         msg = consumer.receive(2000);
         assertNotNull(msg);
         assertTrue(msg instanceof TextMessage);
         assertEquals("group 1 - 2", ((TextMessage) msg).getText());
      } finally {
         connection.close();
      }
   }
 
Example 18
Source File: MQTTOpenwireTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void doTestSendJMSReceiveMQTT(String jmsDestination, String mqttTopic) throws Exception {
   final MQTTClientProvider provider = getMQTTClientProvider();
   initializeConnection(provider);

   ActiveMQConnection activeMQConnection = (ActiveMQConnection) cf.createConnection();
   try {
      activeMQConnection.setUseRetroactiveConsumer(true);
      activeMQConnection.start();
      Session s = activeMQConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      javax.jms.Topic jmsTopic = s.createTopic(jmsDestination);
      MessageProducer producer = s.createProducer(jmsTopic);

      final String RETAINED = "RETAINED";
      provider.subscribe(mqttTopic, AT_MOST_ONCE);

      // send retained message from JMS
      TextMessage sendMessage = s.createTextMessage(RETAINED);
      // mark the message to be retained
      sendMessage.setBooleanProperty("ActiveMQ.Retain", true);
      // MQTT QoS can be set using MQTTProtocolConverter.QOS_PROPERTY_NAME property
      sendMessage.setIntProperty("ActiveMQ.MQTT.QoS", 0);
      producer.send(sendMessage);

      byte[] message = provider.receive(2000);
      assertNotNull("Should get retained message " + jmsDestination + "->" + mqttTopic, message);
      assertEquals(RETAINED, new String(message));

      for (int i = 0; i < 1; i++) {
         String payload = "This is Test Message: " + i;
         sendMessage = s.createTextMessage(payload);
         producer.send(sendMessage);
         message = provider.receive(1000);
         assertNotNull("Should get a message " + jmsDestination + "->" + mqttTopic, message);

         assertEquals(payload, new String(message));
      }
   } finally {
      activeMQConnection.close();
      provider.disconnect();
   }
}
 
Example 19
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 20
Source File: ConsumerPriorityTest.java    From activemq-artemis with Apache License 2.0 2 votes vote down vote up
@Test
public void testConsumerPriorityQueueConsumerRoundRobin() throws Exception {
   ConnectionFactory fact = getCF();
   Connection connection = fact.createConnection();
   String queueName = getName();

   try {

      Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);

      Queue queue = session.createQueue(queueName);
      Queue queue1 = session.createQueue(queueName + "?consumer-priority=3");
      Queue queue2 = session.createQueue(queueName + "?consumer-priority=3");
      Queue queue3 = session.createQueue(queueName + "?consumer-priority=1");


      MessageProducer producer = session.createProducer(queue);

      MessageConsumer consumer1 = session.createConsumer(queue1);
      MessageConsumer consumer2 = session.createConsumer(queue2);
      MessageConsumer consumer3 = session.createConsumer(queue3);

      connection.start();

      for (int j = 0; j < 100; j++) {
         TextMessage message = session.createTextMessage();

         message.setText("Message" + j);
         message.setIntProperty("counter", j);
         producer.send(message);
      }


      //All msgs should go to the first two consumers, round robin'd
      for (int j = 0; j < 50; j += 2) {
         TextMessage tm = (TextMessage) consumer1.receive(10000);

         assertNotNull(tm);

         assertEquals("Message" + j, tm.getText());

         TextMessage tm2 = (TextMessage) consumer2.receive(10000);
         assertNotNull(tm2);

         assertEquals("Message" + (j + 1), tm2.getText());



         TextMessage tm3 = (TextMessage) consumer3.receiveNoWait();
         assertNull(tm3);
      }
   } finally {
      connection.close();
   }
}