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

The following examples show how to use javax.jms.TextMessage#getIntProperty() . 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: JmsSendReceiveTestSupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests if the messages received are valid.
 *
 * @param receivedMessages - list of received messages.
 * @throws JMSException
 */
protected void assertMessagesReceivedAreValid(List<Message> receivedMessages) throws JMSException {
   List<Object> copyOfMessages = Arrays.asList(receivedMessages.toArray());
   int counter = 0;

   if (data.length != copyOfMessages.size()) {
      for (Iterator<Object> iter = copyOfMessages.iterator(); iter.hasNext(); ) {
         TextMessage message = (TextMessage) iter.next();
      }
   }

   assertEquals("Not enough messages received", data.length, receivedMessages.size());

   for (int i = 0; i < data.length; i++) {
      TextMessage received = (TextMessage) receivedMessages.get(i);
      String text = received.getText();
      String stringProperty = received.getStringProperty("stringProperty");
      int intProperty = received.getIntProperty("intProperty");

      assertEquals("Message: " + i, data[i], text);
      assertEquals(data[i], stringProperty);
      assertEquals(i, intProperty);
   }
}
 
Example 2
Source File: JMSXDeliveryCountTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
   try {
      Message lastMessage = null;
      for (int j = 0; j < numRecoveries; j++) {

         for (int i = 0; i < numMessages; i++) {
            TextMessage tm = (TextMessage) cons.receive();
            lastMessage = tm;

            if (tm == null) {
               failed = true;
            } else if (!tm.getText().equals("testing" + i)) {
               failed = true;
            } else if (tm.getIntProperty("JMSXDeliveryCount") != j + 1) {
               failed = true;
            }
         }
         if (j != numRecoveries - 1) {
            sess.recover();
         }

      }
      lastMessage.acknowledge();
   } catch (Exception e) {
      failed = true;
   }
}
 
Example 3
Source File: JmsSendReceiveTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if the messages received are valid.
 *
 * @param receivedMessages - list of received messages.
 * @throws JMSException
 */
protected void assertMessagesReceivedAreValid(List<Message> receivedMessages) throws JMSException {
   List<Object> copyOfMessages = Arrays.asList(receivedMessages.toArray());
   int counter = 0;

   if (data.length != copyOfMessages.size()) {
      for (Iterator<Object> iter = copyOfMessages.iterator(); iter.hasNext(); ) {
         TextMessage message = (TextMessage) iter.next();
         if (LOG.isInfoEnabled()) {
            LOG.info("<== " + counter++ + " = " + message.getText());
         }
      }
   }

   assertEquals("Not enough messages received", data.length, receivedMessages.size());

   for (int i = 0; i < data.length; i++) {
      TextMessage received = (TextMessage) receivedMessages.get(i);
      String text = received.getText();
      String stringProperty = received.getStringProperty("stringProperty");
      int intProperty = received.getIntProperty("intProperty");

      if (verbose) {
         if (LOG.isDebugEnabled()) {
            LOG.info("Received Text: " + text);
         }
      }

      assertEquals("Message: " + i, data[i], text);
      assertEquals(data[i], stringProperty);
      assertEquals(i, intProperty);
   }
}
 
Example 4
Source File: JmsPropertyTypeTest.java    From ballerina-message-broker with Apache License 2.0 4 votes vote down vote up
@Parameters({"broker-port", "admin-username", "admin-password", "broker-hostname"})
@Test
public void testIntProperty(String port,
                              String adminUsername,
                              String adminPassword,
                              String brokerHostname) throws NamingException, JMSException {
    String queueName = "testIntProperty";

    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
            .withQueue(queueName)
            .build();

    ConnectionFactory connectionFactory
            = (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // send messages
    Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = producerSession.createQueue(queueName);
    MessageProducer producer = producerSession.createProducer(queue);
    String intPropertyName = "IntProperty";
    int intProperty = 10;
    TextMessage textMessage = producerSession.createTextMessage("Test message");
    textMessage.setIntProperty(intPropertyName, intProperty);
    producer.send(textMessage);
    producerSession.close();

    // receive messages
    Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
    Session subscriberSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);

    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message, "Message was not received");
    int receivedIntProperty = message.getIntProperty(intPropertyName);
    Assert.assertEquals(intProperty, receivedIntProperty, "Int property not matched.");

    subscriberSession.close();
    connection.close();
}
 
Example 5
Source File: SessionIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
public void testRecoveredClientAckSessionWithDurableSubscriber() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer, false, "?jms.clientID=myClientId", null, null, false);
        connection.start();

        testPeer.expectBegin();

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

        String subscriptionName = "mySubName";
        String topicName = "myTopic";
        Topic topic = session.createTopic(topicName);

        int msgCount = 3;
        testPeer.expectDurableSubscriberAttach(topicName, subscriptionName);
        testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, new AmqpValueDescribedType("content"), msgCount, false, false,
                Matchers.greaterThanOrEqualTo(UnsignedInteger.valueOf(msgCount)), 1, false, true);

        MessageConsumer subscriber = session.createDurableConsumer(topic, subscriptionName);

        TextMessage receivedTextMessage = null;
        assertNotNull("Expected a message", receivedTextMessage = (TextMessage) subscriber.receive(3000));
        assertEquals("Unexpected delivery number", 1,  receivedTextMessage.getIntProperty(TestAmqpPeer.MESSAGE_NUMBER) + 1);
        assertNotNull("Expected a message", receivedTextMessage = (TextMessage) subscriber.receive(3000));
        assertEquals("Unexpected delivery number", 2,  receivedTextMessage.getIntProperty(TestAmqpPeer.MESSAGE_NUMBER) + 1);

        session.recover();

        assertNotNull("Expected a message", receivedTextMessage = (TextMessage) subscriber.receive(3000));
        int deliveryNumber = receivedTextMessage.getIntProperty(TestAmqpPeer.MESSAGE_NUMBER) + 1;
        assertEquals("Unexpected delivery number", 1,  deliveryNumber);

        testPeer.expectDisposition(true, new AcceptedMatcher(), 1, 1);

        receivedTextMessage.acknowledge();

        testPeer.expectDisposition(true, new ModifiedMatcher().withDeliveryFailed(equalTo(true)), 2, 2);
        testPeer.expectDetach(false, true, false);
        testPeer.expectDisposition(true, new ReleasedMatcher(), 3, 3);

        subscriber.close();

        testPeer.waitForAllHandlersToComplete(1000);

        testPeer.expectDurableSubUnsubscribeNullSourceLookup(false, false, subscriptionName, topicName, true);
        testPeer.expectDetach(true, true, true);

        session.unsubscribe(subscriptionName);

        testPeer.expectClose();

        connection.close();
    }
}