org.springframework.jms.support.JmsHeaders Java Examples
The following examples show how to use
org.springframework.jms.support.JmsHeaders.
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: MessagingMessageListenerAdapterTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void buildMessageWithStandardMessage() throws JMSException { Destination replyTo = new Destination() {}; Message<String> result = MessageBuilder.withPayload("Response") .setHeader("foo", "bar") .setHeader(JmsHeaders.TYPE, "msg_type") .setHeader(JmsHeaders.REPLY_TO, replyTo) .build(); Session session = mock(Session.class); given(session.createTextMessage("Response")).willReturn(new StubTextMessage("Response")); MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class); javax.jms.Message replyMessage = listener.buildMessage(session, result); verify(session).createTextMessage("Response"); assertNotNull("reply should never be null", replyMessage); assertEquals("Response", ((TextMessage) replyMessage).getText()); assertEquals("custom header not copied", "bar", replyMessage.getStringProperty("foo")); assertEquals("type header not copied", "msg_type", replyMessage.getJMSType()); assertEquals("replyTo header not copied", replyTo, replyMessage.getJMSReplyTo()); }
Example #2
Source File: JMSConsumer.java From nifi with Apache License 2.0 | 6 votes |
private Map<String, String> extractMessageHeaders(final Message message) throws JMSException { final Map<String, String> messageHeaders = new HashMap<>(); messageHeaders.put(JmsHeaders.DELIVERY_MODE, String.valueOf(message.getJMSDeliveryMode())); messageHeaders.put(JmsHeaders.EXPIRATION, String.valueOf(message.getJMSExpiration())); messageHeaders.put(JmsHeaders.PRIORITY, String.valueOf(message.getJMSPriority())); messageHeaders.put(JmsHeaders.REDELIVERED, String.valueOf(message.getJMSRedelivered())); messageHeaders.put(JmsHeaders.TIMESTAMP, String.valueOf(message.getJMSTimestamp())); messageHeaders.put(JmsHeaders.CORRELATION_ID, message.getJMSCorrelationID()); messageHeaders.put(JmsHeaders.MESSAGE_ID, message.getJMSMessageID()); messageHeaders.put(JmsHeaders.TYPE, message.getJMSType()); String replyToDestinationName = this.retrieveDestinationName(message.getJMSReplyTo(), JmsHeaders.REPLY_TO); if (replyToDestinationName != null) { messageHeaders.put(JmsHeaders.REPLY_TO, replyToDestinationName); } String destinationName = this.retrieveDestinationName(message.getJMSDestination(), JmsHeaders.DESTINATION); if (destinationName != null) { messageHeaders.put(JmsHeaders.DESTINATION, destinationName); } return messageHeaders; }
Example #3
Source File: MessagingMessageListenerAdapterTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void buildMessageWithStandardMessage() throws JMSException { Destination replyTo = new Destination() {}; Message<String> result = MessageBuilder.withPayload("Response") .setHeader("foo", "bar") .setHeader(JmsHeaders.TYPE, "msg_type") .setHeader(JmsHeaders.REPLY_TO, replyTo) .build(); Session session = mock(Session.class); given(session.createTextMessage("Response")).willReturn(new StubTextMessage("Response")); MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class); javax.jms.Message replyMessage = listener.buildMessage(session, result); verify(session).createTextMessage("Response"); assertNotNull("reply should never be null", replyMessage); assertEquals("Response", ((TextMessage) replyMessage).getText()); assertEquals("custom header not copied", "bar", replyMessage.getStringProperty("foo")); assertEquals("type header not copied", "msg_type", replyMessage.getJMSType()); assertEquals("replyTo header not copied", replyTo, replyMessage.getJMSReplyTo()); }
Example #4
Source File: SpringJmsApplicationTest.java From spring-jms with MIT License | 6 votes |
@Test public void testIntegration() throws Exception { MessageChannel producingChannel = applicationContext .getBean("producingChannel", MessageChannel.class); Map<String, Object> headers = Collections.singletonMap( JmsHeaders.DESTINATION, integrationDestination); LOGGER.info("sending 10 messages"); for (int i = 0; i < 10; i++) { GenericMessage<String> message = new GenericMessage<>( "Hello Spring Integration JMS " + i + "!", headers); producingChannel.send(message); LOGGER.info("sent message='{}'", message); } countDownLatchHandler.getLatch().await(10000, TimeUnit.MILLISECONDS); assertThat(countDownLatchHandler.getLatch().getCount()) .isEqualTo(0); }
Example #5
Source File: Receiver.java From spring-jms with MIT License | 6 votes |
@JmsListener(destination = "${destination.order}") public void receiveOrder(String orderNumber, @Header(JmsHeaders.MESSAGE_ID) String messageId) { LOGGER.info("received OrderNumber='{}' with MessageId='{}'", orderNumber, messageId); LOGGER.info("sending Status='Accepted' with CorrelationId='{}'", messageId); jmsTemplate.send(statusDestination, messageCreator -> { TextMessage message = messageCreator.createTextMessage("Accepted"); message.setJMSCorrelationID(messageId); return message; }); }
Example #6
Source File: JMSPublisherConsumerTest.java From solace-integration-guides with Apache License 2.0 | 6 votes |
@Test public void validateJmsHeadersAndPropertiesAreTransferredFromFFAttributes() throws Exception { final String destinationName = "testQueue"; JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false); JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class)); Map<String, String> flowFileAttributes = new HashMap<>(); flowFileAttributes.put("foo", "foo"); flowFileAttributes.put(JmsHeaders.REPLY_TO, "myTopic"); publisher.publish(destinationName, "hellomq".getBytes(), flowFileAttributes); Message receivedMessage = jmsTemplate.receive(destinationName); assertTrue(receivedMessage instanceof BytesMessage); assertEquals("foo", receivedMessage.getStringProperty("foo")); assertTrue(receivedMessage.getJMSReplyTo() instanceof Topic); assertEquals("myTopic", ((Topic) receivedMessage.getJMSReplyTo()).getTopicName()); ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy(); }
Example #7
Source File: JMSPublisherConsumerTest.java From solace-integration-guides with Apache License 2.0 | 6 votes |
@Test public void validateJmsHeadersAndPropertiesAreTransferredFromFFAttributesOverJNDI() throws Exception { final String destinationName = "testQueue"; JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false); JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class)); Map<String, String> flowFileAttributes = new HashMap<>(); flowFileAttributes.put("foo", "foo"); flowFileAttributes.put(JmsHeaders.REPLY_TO, "myTopic"); publisher.publish(destinationName, "hellomq".getBytes(), flowFileAttributes); Message receivedMessage = jmsTemplate.receive(destinationName); assertTrue(receivedMessage instanceof BytesMessage); assertEquals("foo", receivedMessage.getStringProperty("foo")); assertTrue(receivedMessage.getJMSReplyTo() instanceof Topic); assertEquals("myTopic", ((Topic) receivedMessage.getJMSReplyTo()).getTopicName()); ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy(); }
Example #8
Source File: JMSPublisherConsumerTest.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void validateJmsHeadersAndPropertiesAreTransferredFromFFAttributes() throws Exception { final String destinationName = "testQueue"; JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false); JMSPublisher publisher = new JMSPublisher(jmsTemplate, mock(ComponentLog.class)); Map<String, String> flowFileAttributes = new HashMap<>(); flowFileAttributes.put("foo", "foo"); flowFileAttributes.put(JmsHeaders.REPLY_TO, "myTopic"); publisher.publish(destinationName, "hellomq".getBytes(), flowFileAttributes); Message receivedMessage = jmsTemplate.receive(destinationName); assertTrue(receivedMessage instanceof BytesMessage); assertEquals("foo", receivedMessage.getStringProperty("foo")); assertTrue(receivedMessage.getJMSReplyTo() instanceof Topic); assertEquals("myTopic", ((Topic) receivedMessage.getJMSReplyTo()).getTopicName()); ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy(); }
Example #9
Source File: MessagingMessageListenerAdapterTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void buildMessageWithStandardMessage() throws JMSException { Destination replyTo = new Destination() {}; Message<String> result = MessageBuilder.withPayload("Response") .setHeader("foo", "bar") .setHeader(JmsHeaders.TYPE, "msg_type") .setHeader(JmsHeaders.REPLY_TO, replyTo) .build(); Session session = mock(Session.class); given(session.createTextMessage("Response")).willReturn(new StubTextMessage("Response")); MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class); javax.jms.Message replyMessage = listener.buildMessage(session, result); verify(session).createTextMessage("Response"); assertNotNull("reply should never be null", replyMessage); assertEquals("Response", ((TextMessage) replyMessage).getText()); assertEquals("custom header not copied", "bar", replyMessage.getStringProperty("foo")); assertEquals("type header not copied", "msg_type", replyMessage.getJMSType()); assertEquals("replyTo header not copied", replyTo, replyMessage.getJMSReplyTo()); }
Example #10
Source File: PublishJMSTest.java From solace-integration-guides with Apache License 2.0 | 5 votes |
@Test public void validateSuccessfulPublishAndTransferToSuccessOverJNDI() throws Exception { ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) CommonTest.buildJmsJndiConnectionFactory(); final String destinationName = "fooQueue"; PublishJMS pubProc = new PublishJMS(); TestRunner runner = TestRunners.newTestRunner(pubProc); JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class); when(cs.getIdentifier()).thenReturn("cfProvider"); when(cs.getConnectionFactory()).thenReturn(cf); runner.addControllerService("cfProvider", cs); runner.enableControllerService(cs); runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider"); runner.setProperty(PublishJMS.DESTINATION, destinationName); Map<String, String> attributes = new HashMap<>(); attributes.put("foo", "foo"); attributes.put(JmsHeaders.REPLY_TO, "cooQueue"); runner.enqueue("Hey dude!".getBytes(), attributes); runner.run(1, false); final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0); assertNotNull(successFF); JmsTemplate jmst = new JmsTemplate(cf); BytesMessage message = (BytesMessage) jmst.receive(destinationName); byte[] messageBytes = MessageBodyToBytesConverter.toBytes(message); assertEquals("Hey dude!", new String(messageBytes)); assertEquals("cooQueue", ((Queue) message.getJMSReplyTo()).getQueueName()); assertEquals("foo", message.getStringProperty("foo")); }
Example #11
Source File: ConsumeJMSIT.java From nifi with Apache License 2.0 | 5 votes |
@Test public void validateSuccessfulConsumeAndTransferToSuccess() throws Exception { final String destinationName = "cooQueue"; JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false); try { JMSPublisher sender = new JMSPublisher((CachingConnectionFactory) jmsTemplate.getConnectionFactory(), jmsTemplate, mock(ComponentLog.class)); final Map<String, String> senderAttributes = new HashMap<>(); senderAttributes.put("filename", "message.txt"); senderAttributes.put("attribute_from_sender", "some value"); sender.publish(destinationName, "Hey dude!".getBytes(), senderAttributes); TestRunner runner = TestRunners.newTestRunner(new ConsumeJMS()); JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class); when(cs.getIdentifier()).thenReturn("cfProvider"); when(cs.getConnectionFactory()).thenReturn(jmsTemplate.getConnectionFactory()); runner.addControllerService("cfProvider", cs); runner.enableControllerService(cs); runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider"); runner.setProperty(ConsumeJMS.DESTINATION, destinationName); runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.QUEUE); runner.run(1, false); // final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0); assertNotNull(successFF); successFF.assertAttributeExists(JmsHeaders.DESTINATION); successFF.assertAttributeEquals(JmsHeaders.DESTINATION, destinationName); successFF.assertAttributeExists("filename"); successFF.assertAttributeEquals("filename", "message.txt"); successFF.assertAttributeExists("attribute_from_sender"); successFF.assertAttributeEquals("attribute_from_sender", "some value"); successFF.assertAttributeExists("jms.messagetype"); successFF.assertAttributeEquals("jms.messagetype", "BytesMessage"); successFF.assertContentEquals("Hey dude!".getBytes()); String sourceDestination = successFF.getAttribute(ConsumeJMS.JMS_SOURCE_DESTINATION_NAME); assertNotNull(sourceDestination); } finally { ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy(); } }
Example #12
Source File: ConsumeJMSIT.java From nifi with Apache License 2.0 | 5 votes |
/** * Validates <a href="https://issues.apache.org/jira/browse/NIFI-6915">NIFI-6915</a>. * <p> * The test consists on: * <ul> * <li>Start a durable non shared consumer <tt>C1</tt> with client id <tt>client1</tt> subscribed to topic <tt>T</tt>.</li> * <li>Stop <tt>C1</tt>.</li> * <li>Publish a message <tt>M1</tt> to topic <tt>T</tt>.</li> * <li>Start <tt>C1</tt>.</li> * </ul> * It is expected <tt>C1</tt> receives message <tt>M1</tt>. * </p> * @throws Exception * unexpected */ @Test(timeout = 10000) public void validateNifi6915() throws Exception { BrokerService broker = new BrokerService(); try { broker.setPersistent(false); broker.setBrokerName("broker1"); broker.start(); ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://broker1"); final String destinationName = "validateNifi6915"; TestRunner c1Consumer = createNonSharedDurableConsumer(cf, destinationName); // 1. Start a durable non shared consumer C1 with client id client1 subscribed to topic T. boolean stopConsumer = true; c1Consumer.run(1, stopConsumer); List<MockFlowFile> flowFiles = c1Consumer.getFlowFilesForRelationship(ConsumeJMS.REL_SUCCESS); assertTrue("Expected no messages", flowFiles.isEmpty()); // 2. Publish a message M1 to topic T. publishAMessage(cf, destinationName, "Hi buddy!!"); // 3. Start C1. c1Consumer.run(1, true); flowFiles = c1Consumer.getFlowFilesForRelationship(ConsumeJMS.REL_SUCCESS); assertEquals(1, flowFiles.size()); // It is expected C1 receives message M1. final MockFlowFile successFF = flowFiles.get(0); assertNotNull(successFF); successFF.assertAttributeExists(JmsHeaders.DESTINATION); successFF.assertAttributeEquals(JmsHeaders.DESTINATION, destinationName); successFF.assertContentEquals("Hi buddy!!".getBytes()); assertEquals(destinationName, successFF.getAttribute(ConsumeJMS.JMS_SOURCE_DESTINATION_NAME)); } catch (Exception e) { throw e; } finally { if (broker != null) { broker.stop(); } } }
Example #13
Source File: MethodJmsListenerEndpointTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
public void resolveHeaders(String content, @Headers Map<String, Object> headers) { invocations.put("resolveHeaders", true); assertEquals("Wrong payload resolution", "my payload", content); assertNotNull("headers not injected", headers); assertEquals("Missing JMS message id header", "abcd-1234", headers.get(JmsHeaders.MESSAGE_ID)); assertEquals("Missing custom header", 1234, headers.get("customInt")); }
Example #14
Source File: JMSPublisherConsumerIT.java From nifi with Apache License 2.0 | 5 votes |
@Test public void validateJmsHeadersAndPropertiesAreTransferredFromFFAttributes() throws Exception { final String destinationName = "validateJmsHeadersAndPropertiesAreTransferredFromFFAttributes"; JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false); try { JMSPublisher publisher = new JMSPublisher((CachingConnectionFactory) jmsTemplate.getConnectionFactory(), jmsTemplate, mock(ComponentLog.class)); Map<String, String> flowFileAttributes = new HashMap<>(); flowFileAttributes.put("foo", "foo"); flowFileAttributes.put("hyphen-property", "value"); flowFileAttributes.put("fullstop.property", "value"); flowFileAttributes.put(JmsHeaders.REPLY_TO, "myTopic"); flowFileAttributes.put(JmsHeaders.DELIVERY_MODE, "1"); flowFileAttributes.put(JmsHeaders.PRIORITY, "1"); flowFileAttributes.put(JmsHeaders.EXPIRATION, "never"); // value expected to be integer, make sure non-integer doesn't cause problems publisher.publish(destinationName, "hellomq".getBytes(), flowFileAttributes); Message receivedMessage = jmsTemplate.receive(destinationName); assertTrue(receivedMessage instanceof BytesMessage); assertEquals("foo", receivedMessage.getStringProperty("foo")); assertTrue(receivedMessage.propertyExists("hyphen-property")); assertTrue(receivedMessage.propertyExists("fullstop.property")); assertTrue(receivedMessage.getJMSReplyTo() instanceof Topic); assertEquals(1, receivedMessage.getJMSDeliveryMode()); assertEquals(1, receivedMessage.getJMSPriority()); assertEquals("myTopic", ((Topic) receivedMessage.getJMSReplyTo()).getTopicName()); } finally { ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy(); } }
Example #15
Source File: MethodJmsListenerEndpointTests.java From spring-analysis-note with MIT License | 5 votes |
public void resolveHeaders(String content, @Headers Map<String, Object> headers) { this.invocations.put("resolveHeaders", true); assertEquals("Wrong payload resolution", "my payload", content); assertNotNull("headers not injected", headers); assertEquals("Missing JMS message id header", "abcd-1234", headers.get(JmsHeaders.MESSAGE_ID)); assertEquals("Missing custom header", 1234, headers.get("customInt")); }
Example #16
Source File: PublishJMSIT.java From nifi with Apache License 2.0 | 5 votes |
@Test(timeout = 10000) public void validatePublishTextMessage() throws Exception { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); final String destinationName = "validatePublishTextMessage"; PublishJMS pubProc = new PublishJMS(); TestRunner runner = TestRunners.newTestRunner(pubProc); JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class); when(cs.getIdentifier()).thenReturn("cfProvider"); when(cs.getConnectionFactory()).thenReturn(cf); runner.addControllerService("cfProvider", cs); runner.enableControllerService(cs); runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider"); runner.setProperty(PublishJMS.DESTINATION, destinationName); runner.setProperty(PublishJMS.MESSAGE_BODY, "text"); Map<String, String> attributes = new HashMap<>(); attributes.put("foo", "foo"); attributes.put(JmsHeaders.REPLY_TO, "cooQueue"); runner.enqueue("Hey dude!".getBytes(), attributes); runner.run(1, false); final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0); assertNotNull(successFF); JmsTemplate jmst = new JmsTemplate(cf); Message message = jmst.receive(destinationName); assertTrue(message instanceof TextMessage); TextMessage textMessage = (TextMessage) message; byte[] messageBytes = MessageBodyToBytesConverter.toBytes(textMessage); assertEquals("Hey dude!", new String(messageBytes)); assertEquals("cooQueue", ((Queue) message.getJMSReplyTo()).getQueueName()); assertEquals("foo", message.getStringProperty("foo")); runner.run(1, true, false); // Run once just so that we can trigger the shutdown of the Connection Factory }
Example #17
Source File: JMSPublisherConsumerIT.java From nifi with Apache License 2.0 | 5 votes |
@Test public void validateConsumeWithCustomHeadersAndProperties() throws Exception { final String destinationName = "validateConsumeWithCustomHeadersAndProperties"; JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false); try { jmsTemplate.send(destinationName, new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { TextMessage message = session.createTextMessage("hello from the other side"); message.setStringProperty("foo", "foo"); message.setBooleanProperty("bar", false); message.setJMSReplyTo(session.createQueue("fooQueue")); return message; } }); JMSConsumer consumer = new JMSConsumer((CachingConnectionFactory) jmsTemplate.getConnectionFactory(), jmsTemplate, mock(ComponentLog.class)); final AtomicBoolean callbackInvoked = new AtomicBoolean(); consumer.consume(destinationName, null, false, false, null, "UTF-8", new ConsumerCallback() { @Override public void accept(JMSResponse response) { callbackInvoked.set(true); assertEquals("hello from the other side", new String(response.getMessageBody())); assertEquals("fooQueue", response.getMessageHeaders().get(JmsHeaders.REPLY_TO)); assertEquals("foo", response.getMessageProperties().get("foo")); assertEquals("false", response.getMessageProperties().get("bar")); } }); assertTrue(callbackInvoked.get()); } finally { ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy(); } }
Example #18
Source File: ConsumeJMSTest.java From solace-integration-guides with Apache License 2.0 | 5 votes |
@Test public void validateSuccessfulConsumeAndTransferToSuccess() throws Exception { final String destinationName = "cooQueue"; JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false); JMSPublisher sender = new JMSPublisher(jmsTemplate, mock(ComponentLog.class)); final Map<String, String> senderAttributes = new HashMap<>(); senderAttributes.put("filename", "message.txt"); senderAttributes.put("attribute_from_sender", "some value"); sender.publish(destinationName, "Hey dude!".getBytes(), senderAttributes); TestRunner runner = TestRunners.newTestRunner(new ConsumeJMS()); JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class); when(cs.getIdentifier()).thenReturn("cfProvider"); when(cs.getConnectionFactory()).thenReturn(jmsTemplate.getConnectionFactory()); runner.addControllerService("cfProvider", cs); runner.enableControllerService(cs); runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider"); runner.setProperty(ConsumeJMS.DESTINATION, destinationName); runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.QUEUE); runner.run(1, false); // final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0); assertNotNull(successFF); successFF.assertAttributeExists(JmsHeaders.DESTINATION); successFF.assertAttributeEquals(JmsHeaders.DESTINATION, destinationName); successFF.assertAttributeExists("filename"); successFF.assertAttributeEquals("filename", "message.txt"); successFF.assertAttributeExists("attribute_from_sender"); successFF.assertAttributeEquals("attribute_from_sender", "some value"); successFF.assertContentEquals("Hey dude!".getBytes()); String sourceDestination = successFF.getAttribute(ConsumeJMS.JMS_SOURCE_DESTINATION_NAME); assertNotNull(sourceDestination); ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy(); }
Example #19
Source File: PublishJMSTest.java From solace-integration-guides with Apache License 2.0 | 5 votes |
@Test public void validateSuccessfulPublishAndTransferToSuccessWithELOverJNDI() throws Exception { ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) CommonTest.buildJmsJndiConnectionFactory(); final String destinationNameExpression = "${foo}Queue"; final String destinationName = "fooQueue"; PublishJMS pubProc = new PublishJMS(); TestRunner runner = TestRunners.newTestRunner(pubProc); JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class); when(cs.getIdentifier()).thenReturn("cfProvider"); when(cs.getConnectionFactory()).thenReturn(cf); runner.addControllerService("cfProvider", cs); runner.enableControllerService(cs); runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider"); runner.setProperty(PublishJMS.DESTINATION, destinationNameExpression); Map<String, String> attributes = new HashMap<>(); attributes.put("foo", "foo"); attributes.put(JmsHeaders.REPLY_TO, "cooQueue"); runner.enqueue("Hey dude!".getBytes(), attributes); runner.run(1, false); final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0); assertNotNull(successFF); JmsTemplate jmst = new JmsTemplate(cf); BytesMessage message = (BytesMessage) jmst.receive(destinationName); byte[] messageBytes = MessageBodyToBytesConverter.toBytes(message); assertEquals("Hey dude!", new String(messageBytes)); assertEquals("cooQueue", ((Queue) message.getJMSReplyTo()).getQueueName()); assertEquals("foo", message.getStringProperty("foo")); }
Example #20
Source File: PublishJMSTest.java From solace-integration-guides with Apache License 2.0 | 5 votes |
@Test public void validateSuccessfulPublishAndTransferToSuccessWithEL() throws Exception { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); final String destinationNameExpression = "${foo}Queue"; final String destinationName = "fooQueue"; PublishJMS pubProc = new PublishJMS(); TestRunner runner = TestRunners.newTestRunner(pubProc); JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class); when(cs.getIdentifier()).thenReturn("cfProvider"); when(cs.getConnectionFactory()).thenReturn(cf); runner.addControllerService("cfProvider", cs); runner.enableControllerService(cs); runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider"); runner.setProperty(PublishJMS.DESTINATION, destinationNameExpression); Map<String, String> attributes = new HashMap<>(); attributes.put("foo", "foo"); attributes.put(JmsHeaders.REPLY_TO, "cooQueue"); runner.enqueue("Hey dude!".getBytes(), attributes); runner.run(1, false); final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0); assertNotNull(successFF); JmsTemplate jmst = new JmsTemplate(cf); BytesMessage message = (BytesMessage) jmst.receive(destinationName); byte[] messageBytes = MessageBodyToBytesConverter.toBytes(message); assertEquals("Hey dude!", new String(messageBytes)); assertEquals("cooQueue", ((Queue) message.getJMSReplyTo()).getQueueName()); assertEquals("foo", message.getStringProperty("foo")); }
Example #21
Source File: JMSConsumer.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * * */ private Map<String, Object> extractMessageHeaders(Message message) { // even though all values are Strings in current impl, it may change in // the future, so keeping it <String, Object> Map<String, Object> messageHeaders = new HashMap<>(); try { messageHeaders.put(JmsHeaders.DELIVERY_MODE, String.valueOf(message.getJMSDeliveryMode())); messageHeaders.put(JmsHeaders.EXPIRATION, String.valueOf(message.getJMSExpiration())); messageHeaders.put(JmsHeaders.PRIORITY, String.valueOf(message.getJMSPriority())); messageHeaders.put(JmsHeaders.REDELIVERED, String.valueOf(message.getJMSRedelivered())); messageHeaders.put(JmsHeaders.TIMESTAMP, String.valueOf(message.getJMSTimestamp())); messageHeaders.put(JmsHeaders.CORRELATION_ID, message.getJMSCorrelationID()); messageHeaders.put(JmsHeaders.MESSAGE_ID, message.getJMSMessageID()); messageHeaders.put(JmsHeaders.TYPE, message.getJMSType()); String replyToDestinationName = this.retrieveDestinationName(message.getJMSReplyTo(), JmsHeaders.REPLY_TO); if (replyToDestinationName != null) { messageHeaders.put(JmsHeaders.REPLY_TO, replyToDestinationName); } String destinationName = this.retrieveDestinationName(message.getJMSDestination(), JmsHeaders.DESTINATION); if (destinationName != null) { messageHeaders.put(JmsHeaders.DESTINATION, destinationName); } } catch (Exception e) { throw new IllegalStateException("Failed to extract JMS Headers", e); } return messageHeaders; }
Example #22
Source File: PublishJMSTest.java From solace-integration-guides with Apache License 2.0 | 5 votes |
@Test public void validateSuccessfulPublishAndTransferToSuccess() throws Exception { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); final String destinationName = "fooQueue"; PublishJMS pubProc = new PublishJMS(); TestRunner runner = TestRunners.newTestRunner(pubProc); JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class); when(cs.getIdentifier()).thenReturn("cfProvider"); when(cs.getConnectionFactory()).thenReturn(cf); runner.addControllerService("cfProvider", cs); runner.enableControllerService(cs); runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider"); runner.setProperty(PublishJMS.DESTINATION, destinationName); Map<String, String> attributes = new HashMap<>(); attributes.put("foo", "foo"); attributes.put(JmsHeaders.REPLY_TO, "cooQueue"); runner.enqueue("Hey dude!".getBytes(), attributes); runner.run(1, false); final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0); assertNotNull(successFF); JmsTemplate jmst = new JmsTemplate(cf); BytesMessage message = (BytesMessage) jmst.receive(destinationName); byte[] messageBytes = MessageBodyToBytesConverter.toBytes(message); assertEquals("Hey dude!", new String(messageBytes)); assertEquals("cooQueue", ((Queue) message.getJMSReplyTo()).getQueueName()); assertEquals("foo", message.getStringProperty("foo")); }
Example #23
Source File: JMSPublisherConsumerTest.java From solace-integration-guides with Apache License 2.0 | 5 votes |
@Test public void validateConsumeWithCustomHeadersAndPropertiesOverJNDI() throws Exception { final String destinationName = "testQueue"; JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false); jmsTemplate.send(destinationName, new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { TextMessage message = session.createTextMessage("hello from the other side"); message.setStringProperty("foo", "foo"); message.setBooleanProperty("bar", false); message.setJMSReplyTo(session.createQueue("fooQueue")); return message; } }); JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class)); final AtomicBoolean callbackInvoked = new AtomicBoolean(); consumer.consume(destinationName, new ConsumerCallback() { @Override public void accept(JMSResponse response) { callbackInvoked.set(true); assertEquals("hello from the other side", new String(response.getMessageBody())); assertEquals("fooQueue", response.getMessageHeaders().get(JmsHeaders.REPLY_TO)); assertEquals("foo", response.getMessageProperties().get("foo")); assertEquals("false", response.getMessageProperties().get("bar")); } }); assertTrue(callbackInvoked.get()); ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy(); }
Example #24
Source File: JMSPublisherConsumerTest.java From solace-integration-guides with Apache License 2.0 | 5 votes |
@Test public void validateConsumeWithCustomHeadersAndProperties() throws Exception { final String destinationName = "testQueue"; JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false); jmsTemplate.send(destinationName, new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { TextMessage message = session.createTextMessage("hello from the other side"); message.setStringProperty("foo", "foo"); message.setBooleanProperty("bar", false); message.setJMSReplyTo(session.createQueue("fooQueue")); return message; } }); JMSConsumer consumer = new JMSConsumer(jmsTemplate, mock(ComponentLog.class)); final AtomicBoolean callbackInvoked = new AtomicBoolean(); consumer.consume(destinationName, new ConsumerCallback() { @Override public void accept(JMSResponse response) { callbackInvoked.set(true); assertEquals("hello from the other side", new String(response.getMessageBody())); assertEquals("fooQueue", response.getMessageHeaders().get(JmsHeaders.REPLY_TO)); assertEquals("foo", response.getMessageProperties().get("foo")); assertEquals("false", response.getMessageProperties().get("bar")); } }); assertTrue(callbackInvoked.get()); ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy(); }
Example #25
Source File: PublishJMSIT.java From nifi with Apache License 2.0 | 5 votes |
@Test(timeout = 10000) public void validateSuccessfulPublishAndTransferToSuccessWithEL() throws Exception { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); final String destinationNameExpression = "${foo}Queue"; final String destinationName = "fooQueue"; PublishJMS pubProc = new PublishJMS(); TestRunner runner = TestRunners.newTestRunner(pubProc); JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class); when(cs.getIdentifier()).thenReturn("cfProvider"); when(cs.getConnectionFactory()).thenReturn(cf); runner.addControllerService("cfProvider", cs); runner.enableControllerService(cs); runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider"); runner.setProperty(PublishJMS.DESTINATION, destinationNameExpression); Map<String, String> attributes = new HashMap<>(); attributes.put("foo", "foo"); attributes.put(JmsHeaders.REPLY_TO, "cooQueue"); runner.enqueue("Hey dude!".getBytes(), attributes); runner.run(1, false); // Run once but don't shut down because we want the Connection Factory left in tact so that we can use it. final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0); assertNotNull(successFF); JmsTemplate jmst = new JmsTemplate(cf); BytesMessage message = (BytesMessage) jmst.receive(destinationName); byte[] messageBytes = MessageBodyToBytesConverter.toBytes(message); assertEquals("Hey dude!", new String(messageBytes)); assertEquals("cooQueue", ((Queue) message.getJMSReplyTo()).getQueueName()); assertEquals("foo", message.getStringProperty("foo")); runner.run(1, true, false); // Run once just so that we can trigger the shutdown of the Connection Factory }
Example #26
Source File: MethodJmsListenerEndpointTests.java From java-technology-stack with MIT License | 5 votes |
public void resolveHeaders(String content, @Headers Map<String, Object> headers) { this.invocations.put("resolveHeaders", true); assertEquals("Wrong payload resolution", "my payload", content); assertNotNull("headers not injected", headers); assertEquals("Missing JMS message id header", "abcd-1234", headers.get(JmsHeaders.MESSAGE_ID)); assertEquals("Missing custom header", 1234, headers.get("customInt")); }
Example #27
Source File: JMSConsumer.java From solace-integration-guides with Apache License 2.0 | 5 votes |
/** * * */ private Map<String, Object> extractMessageHeaders(Message message) { // even though all values are Strings in current impl, it may change in // the future, so keeping it <String, Object> Map<String, Object> messageHeaders = new HashMap<>(); try { messageHeaders.put(JmsHeaders.DELIVERY_MODE, String.valueOf(message.getJMSDeliveryMode())); messageHeaders.put(JmsHeaders.EXPIRATION, String.valueOf(message.getJMSExpiration())); messageHeaders.put(JmsHeaders.PRIORITY, String.valueOf(message.getJMSPriority())); messageHeaders.put(JmsHeaders.REDELIVERED, String.valueOf(message.getJMSRedelivered())); messageHeaders.put(JmsHeaders.TIMESTAMP, String.valueOf(message.getJMSTimestamp())); messageHeaders.put(JmsHeaders.CORRELATION_ID, message.getJMSCorrelationID()); messageHeaders.put(JmsHeaders.MESSAGE_ID, message.getJMSMessageID()); messageHeaders.put(JmsHeaders.TYPE, message.getJMSType()); String replyToDestinationName = this.retrieveDestinationName(message.getJMSReplyTo(), JmsHeaders.REPLY_TO); if (replyToDestinationName != null) { messageHeaders.put(JmsHeaders.REPLY_TO, replyToDestinationName); } String destinationName = this.retrieveDestinationName(message.getJMSDestination(), JmsHeaders.DESTINATION); if (destinationName != null) { messageHeaders.put(JmsHeaders.DESTINATION, destinationName); } } catch (Exception e) { throw new IllegalStateException("Failed to extract JMS Headers", e); } return messageHeaders; }
Example #28
Source File: ConsumeJMSTest.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void validateSuccessfulConsumeAndTransferToSuccess() throws Exception { final String destinationName = "cooQueue"; JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false); JMSPublisher sender = new JMSPublisher(jmsTemplate, mock(ComponentLog.class)); final Map<String, String> senderAttributes = new HashMap<>(); senderAttributes.put("filename", "message.txt"); senderAttributes.put("attribute_from_sender", "some value"); sender.publish(destinationName, "Hey dude!".getBytes(), senderAttributes); TestRunner runner = TestRunners.newTestRunner(new ConsumeJMS()); JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class); when(cs.getIdentifier()).thenReturn("cfProvider"); when(cs.getConnectionFactory()).thenReturn(jmsTemplate.getConnectionFactory()); runner.addControllerService("cfProvider", cs); runner.enableControllerService(cs); runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider"); runner.setProperty(ConsumeJMS.DESTINATION, destinationName); runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.QUEUE); runner.run(1, false); // final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0); assertNotNull(successFF); successFF.assertAttributeExists(JmsHeaders.DESTINATION); successFF.assertAttributeEquals(JmsHeaders.DESTINATION, destinationName); successFF.assertAttributeExists("filename"); successFF.assertAttributeEquals("filename", "message.txt"); successFF.assertAttributeExists("attribute_from_sender"); successFF.assertAttributeEquals("attribute_from_sender", "some value"); successFF.assertContentEquals("Hey dude!".getBytes()); String sourceDestination = successFF.getAttribute(ConsumeJMS.JMS_SOURCE_DESTINATION_NAME); assertNotNull(sourceDestination); ((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy(); }
Example #29
Source File: PublishJMSTest.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void validateSuccessfulPublishAndTransferToSuccessWithEL() throws Exception { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); final String destinationNameExpression = "${foo}Queue"; final String destinationName = "fooQueue"; PublishJMS pubProc = new PublishJMS(); TestRunner runner = TestRunners.newTestRunner(pubProc); JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class); when(cs.getIdentifier()).thenReturn("cfProvider"); when(cs.getConnectionFactory()).thenReturn(cf); runner.addControllerService("cfProvider", cs); runner.enableControllerService(cs); runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider"); runner.setProperty(PublishJMS.DESTINATION, destinationNameExpression); Map<String, String> attributes = new HashMap<>(); attributes.put("foo", "foo"); attributes.put(JmsHeaders.REPLY_TO, "cooQueue"); runner.enqueue("Hey dude!".getBytes(), attributes); runner.run(1, false); final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0); assertNotNull(successFF); JmsTemplate jmst = new JmsTemplate(cf); BytesMessage message = (BytesMessage) jmst.receive(destinationName); byte[] messageBytes = MessageBodyToBytesConverter.toBytes(message); assertEquals("Hey dude!", new String(messageBytes)); assertEquals("cooQueue", ((Queue) message.getJMSReplyTo()).getQueueName()); assertEquals("foo", message.getStringProperty("foo")); }
Example #30
Source File: PublishJMSTest.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void validateSuccessfulPublishAndTransferToSuccess() throws Exception { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); final String destinationName = "fooQueue"; PublishJMS pubProc = new PublishJMS(); TestRunner runner = TestRunners.newTestRunner(pubProc); JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class); when(cs.getIdentifier()).thenReturn("cfProvider"); when(cs.getConnectionFactory()).thenReturn(cf); runner.addControllerService("cfProvider", cs); runner.enableControllerService(cs); runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider"); runner.setProperty(PublishJMS.DESTINATION, destinationName); Map<String, String> attributes = new HashMap<>(); attributes.put("foo", "foo"); attributes.put(JmsHeaders.REPLY_TO, "cooQueue"); runner.enqueue("Hey dude!".getBytes(), attributes); runner.run(1, false); final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0); assertNotNull(successFF); JmsTemplate jmst = new JmsTemplate(cf); BytesMessage message = (BytesMessage) jmst.receive(destinationName); byte[] messageBytes = MessageBodyToBytesConverter.toBytes(message); assertEquals("Hey dude!", new String(messageBytes)); assertEquals("cooQueue", ((Queue) message.getJMSReplyTo()).getQueueName()); assertEquals("foo", message.getStringProperty("foo")); }