Search in sources :

Example 66 with Message

use of javax.jms.Message in project wildfly by wildfly.

the class JMSQueueManagementTestCase method testMessageRemoval.

//    @org.junit.Ignore("AS7-2480")
@Test
public void testMessageRemoval() throws Exception {
    MessageProducer producer = session.createProducer(queue);
    Message msgA = session.createTextMessage("A");
    producer.send(msgA);
    producer.send(session.createTextMessage("B"));
    producer.send(session.createTextMessage("C"));
    final ModelNode op = getQueueOperation("remove-message");
    op.get("message-id").set(msgA.getJMSMessageID());
    ModelNode result = execute(op, true);
    Assert.assertTrue(result.isDefined());
    Assert.assertTrue(result.asBoolean());
    result = execute(getQueueOperation("count-messages"), true);
    Assert.assertTrue(result.isDefined());
    Assert.assertEquals(2, result.asInt());
    result = execute(getQueueOperation("remove-messages"), true);
    Assert.assertTrue(result.isDefined());
    Assert.assertEquals(2, result.asInt());
    result = execute(getQueueOperation("count-messages"), true);
    Assert.assertTrue(result.isDefined());
    Assert.assertEquals(0, result.asInt());
}
Also used : Message(javax.jms.Message) MessageProducer(javax.jms.MessageProducer) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 67 with Message

use of javax.jms.Message in project beam by apache.

the class JmsCheckpointMark method finalizeCheckpoint.

/**
   * Acknowledge all outstanding message. Since we believe that messages will be delivered in
   * timestamp order, and acknowledged messages will not be retried, the newest message in this
   * batch is a good bound for future messages.
   */
@Override
public void finalizeCheckpoint() {
    for (Message message : messages) {
        try {
            message.acknowledge();
            Instant currentMessageTimestamp = new Instant(message.getJMSTimestamp());
            if (currentMessageTimestamp.isAfter(oldestPendingTimestamp)) {
                oldestPendingTimestamp = currentMessageTimestamp;
            }
        } catch (Exception e) {
        // nothing to do
        }
    }
    messages.clear();
}
Also used : Message(javax.jms.Message) Instant(org.joda.time.Instant)

Example 68 with Message

use of javax.jms.Message in project beam by apache.

the class JmsIOTest method testReadMessages.

@Test
public void testReadMessages() throws Exception {
    // produce message
    Connection connection = connectionFactory.createConnection(USERNAME, PASSWORD);
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(session.createQueue(QUEUE));
    TextMessage message = session.createTextMessage("This Is A Test");
    producer.send(message);
    producer.send(message);
    producer.send(message);
    producer.send(message);
    producer.send(message);
    producer.send(message);
    producer.close();
    session.close();
    connection.close();
    // read from the queue
    PCollection<JmsRecord> output = pipeline.apply(JmsIO.read().withConnectionFactory(connectionFactory).withQueue(QUEUE).withUsername(USERNAME).withPassword(PASSWORD).withMaxNumRecords(5));
    PAssert.thatSingleton(output.apply("Count", Count.<JmsRecord>globally())).isEqualTo(new Long(5));
    pipeline.run();
    connection = connectionFactory.createConnection(USERNAME, PASSWORD);
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(session.createQueue(QUEUE));
    Message msg = consumer.receiveNoWait();
    assertNull(msg);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 69 with Message

use of javax.jms.Message in project spring-boot by spring-projects.

the class ArtemisAutoConfigurationTests method embeddedWithPersistentMode.

@Test
public void embeddedWithPersistentMode() throws IOException, JMSException {
    File dataFolder = this.folder.newFolder();
    // Start the server and post a message to some queue
    load(EmptyConfiguration.class, "spring.artemis.embedded.queues=TestQueue", "spring.artemis.embedded.persistent:true", "spring.artemis.embedded.dataDirectory:" + dataFolder.getAbsolutePath());
    final String msgId = UUID.randomUUID().toString();
    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    jmsTemplate.send("TestQueue", new MessageCreator() {

        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage(msgId);
        }
    });
    // Shutdown the broker
    this.context.close();
    // Start the server again and check if our message is still here
    load(EmptyConfiguration.class, "spring.artemis.embedded.queues=TestQueue", "spring.artemis.embedded.persistent:true", "spring.artemis.embedded.dataDirectory:" + dataFolder.getAbsolutePath());
    JmsTemplate jmsTemplate2 = this.context.getBean(JmsTemplate.class);
    jmsTemplate2.setReceiveTimeout(1000L);
    Message message = jmsTemplate2.receive("TestQueue");
    assertThat(message).isNotNull();
    assertThat(((TextMessage) message).getText()).isEqualTo(msgId);
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JmsTemplate(org.springframework.jms.core.JmsTemplate) JMSException(javax.jms.JMSException) File(java.io.File) MessageCreator(org.springframework.jms.core.MessageCreator) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 70 with Message

use of javax.jms.Message in project play-cookbook by spinscale.

the class ActiveMqTest method assertThatPluginSendsMessages.

@Test
public void assertThatPluginSendsMessages() throws Exception {
    assertEquals(0, ChatRoom.get().archive().size());
    Event event = new Join("user");
    ChatRoom.get().publish(event);
    // Check chatroom
    int currentEventCount = ChatRoom.get().archive().size();
    assertEquals(1, currentEventCount);
    // Check for messages
    Message msg = receiveSubscriber.receive(2000);
    Event evt = (ChatRoom.Event) ((ObjectMessage) msg).getObject();
    assertEquals("join", evt.type);
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) Event(models.ChatRoom.Event) Join(models.ChatRoom.Join) UnitTest(play.test.UnitTest) Test(org.junit.Test)

Aggregations

Message (javax.jms.Message)230 TextMessage (javax.jms.TextMessage)103 Test (org.junit.Test)91 Session (javax.jms.Session)86 JMSException (javax.jms.JMSException)77 MessageProducer (javax.jms.MessageProducer)64 ObjectMessage (javax.jms.ObjectMessage)52 MessageConsumer (javax.jms.MessageConsumer)50 Connection (javax.jms.Connection)45 BytesMessage (javax.jms.BytesMessage)37 Destination (javax.jms.Destination)30 MapMessage (javax.jms.MapMessage)26 Queue (javax.jms.Queue)20 ConnectionFactory (javax.jms.ConnectionFactory)18 QueueSession (javax.jms.QueueSession)17 MessageCreator (org.springframework.jms.core.MessageCreator)15 MessageListener (javax.jms.MessageListener)12 Map (java.util.Map)10 StreamMessage (javax.jms.StreamMessage)10 TemporaryQueue (javax.jms.TemporaryQueue)9