Java Code Examples for javax.jms.JMSContext#createMessage()
The following examples show how to use
javax.jms.JMSContext#createMessage() .
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: JmsContextTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testGetAnotherContextFromIt() { JMSContext c2 = context.createContext(Session.DUPS_OK_ACKNOWLEDGE); Assert.assertNotNull(c2); Assert.assertEquals(Session.DUPS_OK_ACKNOWLEDGE, c2.getSessionMode()); Message m2 = c2.createMessage(); Assert.assertNotNull(m2); c2.close(); // should close its session, but not its (shared) connection try { c2.createMessage(); Assert.fail("session should be closed..."); } catch (JMSRuntimeException expected) { // expected } Message m1 = context.createMessage(); Assert.assertNotNull("connection must be open", m1); }
Example 2
Source File: JmsPoolJMSContextTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 30000) public void testCreateMessage() { JMSContext context = cf.createContext(); assertNotNull(context.createMessage()); context.close(); try { context.createMessage(); fail("Should not be able to create resource when context is closed"); } catch (IllegalStateRuntimeException isre) {} }
Example 3
Source File: JmsContextTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testCloseSecondContextConnectionRemainsOpen() throws JMSException { JMSContext localContext = context.createContext(JMSContext.CLIENT_ACKNOWLEDGE); Assert.assertEquals("client_ack", JMSContext.CLIENT_ACKNOWLEDGE, localContext.getSessionMode()); JMSProducer producer = localContext.createProducer(); JMSConsumer consumer = localContext.createConsumer(queue1); final int pass = 1; for (int idx = 0; idx < 2; idx++) { Message m = localContext.createMessage(); int intProperty = random.nextInt(); m.setIntProperty("random", intProperty); Assert.assertNotNull(m); producer.send(queue1, m); m = null; Message msg = consumer.receive(100); Assert.assertNotNull("must have a msg", msg); Assert.assertEquals(intProperty, msg.getIntProperty("random")); /* In the second pass we close the connection before ack'ing */ if (idx == pass) { localContext.close(); } /** * From {@code JMSContext.close()}'s javadoc:<br/> * Invoking the {@code acknowledge} method of a received message from a closed connection's * session must throw an {@code IllegalStateRuntimeException}. Closing a closed connection * must NOT throw an exception. */ try { msg.acknowledge(); Assert.assertEquals("connection should be open on pass 0. It is " + pass, 0, idx); } catch (javax.jms.IllegalStateException expected) { // HORNETQ-1209 "JMS 2.0" XXX JMSContext javadoc says we must expect a // IllegalStateRuntimeException here. But Message.ack...() says it must throws the // non-runtime variant. Assert.assertEquals("we only close the connection on pass " + pass, pass, idx); } } }
Example 4
Source File: JMSProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testJMSProducerPropertyOverridesMessageValue() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JMSContext context = testFixture.createJMSContext(testPeer, SERVER_ANONYMOUS_RELAY); testPeer.expectBegin(); testPeer.expectSenderAttach(); String queueName = "myQueue"; Queue queue = context.createQueue(queueName); Message message = context.createMessage(); JMSProducer producer = context.createProducer(); ApplicationPropertiesSectionMatcher appPropsMatcher = new ApplicationPropertiesSectionMatcher(true); appPropsMatcher.withEntry(STRING_PROP, equalTo(STRING_PROP_VALUE)); MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true).withDurable(equalTo(true)); MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true); MessagePropertiesSectionMatcher propsMatcher = new MessagePropertiesSectionMatcher(true).withTo(equalTo(queueName)); TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); messageMatcher.setHeadersMatcher(headersMatcher); messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher); messageMatcher.setPropertiesMatcher(propsMatcher); messageMatcher.setApplicationPropertiesMatcher(appPropsMatcher); testPeer.expectTransfer(messageMatcher); message.setStringProperty(STRING_PROP, "ThisShouldNotBeTransmitted"); producer.setProperty(STRING_PROP, STRING_PROP_VALUE); producer.send(queue, message); testPeer.expectEnd(); testPeer.expectClose(); context.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 5
Source File: JMSProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout = 20000) public void testCreateProducerAndSend() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JMSContext context = testFixture.createJMSContext(testPeer, SERVER_ANONYMOUS_RELAY); testPeer.expectBegin(); //Expect a link to the anonymous relay node TargetMatcher targetMatcher = new TargetMatcher(); targetMatcher.withAddress(nullValue()); targetMatcher.withDynamic(nullValue());//default = false targetMatcher.withDurable(nullValue());//default = none/0 testPeer.expectSenderAttach(targetMatcher, false, false); JMSProducer producer = context.createProducer(); assertNotNull(producer); String topicName = "testCreateProducerAndSend"; Topic topic = context.createTopic(topicName); // Verify sent message contains expected destination address and dest type annotation MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true); Symbol annotationKey = AmqpDestinationHelper.JMS_DEST_TYPE_MSG_ANNOTATION_SYMBOL; msgAnnotationsMatcher.withEntry(annotationKey, equalTo(AmqpDestinationHelper.TOPIC_TYPE)); MessagePropertiesSectionMatcher propsMatcher = new MessagePropertiesSectionMatcher(true).withTo(equalTo(topicName)); TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); messageMatcher.setHeadersMatcher(new MessageHeaderSectionMatcher(true).withDurable(equalTo(true))); messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher); messageMatcher.setPropertiesMatcher(propsMatcher); testPeer.expectTransfer(messageMatcher); Message message = context.createMessage(); producer.send(topic, message); testPeer.expectEnd(); testPeer.expectClose(); context.close(); testPeer.waitForAllHandlersToComplete(1000); } }