javax.jms.Message.getJMSReplyTo()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(204)

本文整理了Java中javax.jms.Message.getJMSReplyTo()方法的一些代码示例,展示了Message.getJMSReplyTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getJMSReplyTo()方法的具体详情如下:
包路径:javax.jms.Message
类名称:Message
方法名:getJMSReplyTo

Message.getJMSReplyTo介绍

[英]Gets the Destination object to which a reply to this message should be sent.
[中]获取应向其发送对此消息的答复的目标对象。

代码示例

代码示例来源:origin: spring-projects/spring-framework

  1. /**
  2. * Send the given RemoteInvocationResult as a JMS message to the originator.
  3. * @param requestMessage current request message
  4. * @param session the JMS Session to use
  5. * @param result the RemoteInvocationResult object
  6. * @throws javax.jms.JMSException if thrown by trying to send the message
  7. */
  8. protected void writeRemoteInvocationResult(
  9. Message requestMessage, Session session, RemoteInvocationResult result) throws JMSException {
  10. Message response = createResponseMessage(requestMessage, session, result);
  11. MessageProducer producer = session.createProducer(requestMessage.getJMSReplyTo());
  12. try {
  13. producer.send(response);
  14. }
  15. finally {
  16. JmsUtils.closeMessageProducer(producer);
  17. }
  18. }

代码示例来源:origin: spring-projects/spring-framework

  1. /**
  2. * Determine a response destination for the given message.
  3. * <p>The default implementation first checks the JMS Reply-To
  4. * {@link Destination} of the supplied request; if that is not {@code null}
  5. * it is returned; if it is {@code null}, then the configured
  6. * {@link #resolveDefaultResponseDestination default response destination}
  7. * is returned; if this too is {@code null}, then an
  8. * {@link javax.jms.InvalidDestinationException} is thrown.
  9. * @param request the original incoming JMS message
  10. * @param response the outgoing JMS message about to be sent
  11. * @param session the JMS Session to operate on
  12. * @return the response destination (never {@code null})
  13. * @throws JMSException if thrown by JMS API methods
  14. * @throws javax.jms.InvalidDestinationException if no {@link Destination} can be determined
  15. * @see #setDefaultResponseDestination
  16. * @see javax.jms.Message#getJMSReplyTo()
  17. */
  18. protected Destination getResponseDestination(Message request, Message response, Session session)
  19. throws JMSException {
  20. Destination replyTo = request.getJMSReplyTo();
  21. if (replyTo == null) {
  22. replyTo = resolveDefaultResponseDestination(session);
  23. if (replyTo == null) {
  24. throw new InvalidDestinationException("Cannot determine response destination: " +
  25. "Request message does not contain reply-to destination, and no default response destination set.");
  26. }
  27. }
  28. return replyTo;
  29. }

代码示例来源:origin: log4j/log4j

  1. sbuf.append(m.getJMSReplyTo());

代码示例来源:origin: spring-projects/spring-framework

  1. Destination replyTo = jmsMessage.getJMSReplyTo();
  2. if (replyTo != null) {
  3. headers.put(JmsHeaders.REPLY_TO, replyTo);

代码示例来源:origin: apache/nifi

  1. private Map<String, String> extractMessageHeaders(final Message message) throws JMSException {
  2. final Map<String, String> messageHeaders = new HashMap<>();
  3. messageHeaders.put(JmsHeaders.DELIVERY_MODE, String.valueOf(message.getJMSDeliveryMode()));
  4. messageHeaders.put(JmsHeaders.EXPIRATION, String.valueOf(message.getJMSExpiration()));
  5. messageHeaders.put(JmsHeaders.PRIORITY, String.valueOf(message.getJMSPriority()));
  6. messageHeaders.put(JmsHeaders.REDELIVERED, String.valueOf(message.getJMSRedelivered()));
  7. messageHeaders.put(JmsHeaders.TIMESTAMP, String.valueOf(message.getJMSTimestamp()));
  8. messageHeaders.put(JmsHeaders.CORRELATION_ID, message.getJMSCorrelationID());
  9. messageHeaders.put(JmsHeaders.MESSAGE_ID, message.getJMSMessageID());
  10. messageHeaders.put(JmsHeaders.TYPE, message.getJMSType());
  11. String replyToDestinationName = this.retrieveDestinationName(message.getJMSReplyTo(), JmsHeaders.REPLY_TO);
  12. if (replyToDestinationName != null) {
  13. messageHeaders.put(JmsHeaders.REPLY_TO, replyToDestinationName);
  14. }
  15. String destinationName = this.retrieveDestinationName(message.getJMSDestination(), JmsHeaders.DESTINATION);
  16. if (destinationName != null) {
  17. messageHeaders.put(JmsHeaders.DESTINATION, destinationName);
  18. }
  19. return messageHeaders;
  20. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void jmsReplyToMappedFromHeader() throws JMSException {
  3. Destination replyTo = new Destination() {};
  4. Message<String> message = initBuilder()
  5. .setHeader(JmsHeaders.REPLY_TO, replyTo).build();
  6. javax.jms.Message jmsMessage = new StubTextMessage();
  7. mapper.fromHeaders(message.getHeaders(), jmsMessage);
  8. assertNotNull(jmsMessage.getJMSReplyTo());
  9. assertSame(replyTo, jmsMessage.getJMSReplyTo());
  10. }

代码示例来源:origin: apache/nifi

  1. attributes.put(ATTRIBUTE_PREFIX + JMS_MESSAGE_ID, message.getJMSMessageID());
  2. if (message.getJMSReplyTo() != null) {
  3. attributes.put(ATTRIBUTE_PREFIX + JMS_REPLY_TO, message.getJMSReplyTo().toString());

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException {
  3. Session mockExporterSession = mock(Session.class);
  4. ResponseStoringProducer mockProducer = new ResponseStoringProducer();
  5. given(mockExporterSession.createProducer(requestMessage.getJMSReplyTo())).willReturn(mockProducer);
  6. exporter.onMessage(requestMessage, mockExporterSession);
  7. assertTrue(mockProducer.closed);
  8. return mockProducer.response;
  9. }
  10. };

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void JmsReplyToIgnoredIfIncorrectType() throws JMSException {
  3. Message<String> message = initBuilder()
  4. .setHeader(JmsHeaders.REPLY_TO, "not-a-destination").build();
  5. javax.jms.Message jmsMessage = new StubTextMessage();
  6. mapper.fromHeaders(message.getHeaders(), jmsMessage);
  7. assertNull(jmsMessage.getJMSReplyTo());
  8. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void attemptToWriteDisallowedReplyToPropertyIsNotFatal() throws JMSException {
  3. Message<String> message = initBuilder()
  4. .setHeader(JmsHeaders.REPLY_TO, new Destination() {})
  5. .setHeader("foo", "bar")
  6. .build();
  7. javax.jms.Message jmsMessage = new StubTextMessage() {
  8. @Override
  9. public void setJMSReplyTo(Destination replyTo) throws JMSException {
  10. throw new JMSException("illegal property");
  11. }
  12. };
  13. mapper.fromHeaders(message.getHeaders(), jmsMessage);
  14. assertNull(jmsMessage.getJMSReplyTo());
  15. assertNotNull(jmsMessage.getStringProperty("foo"));
  16. assertEquals("bar", jmsMessage.getStringProperty("foo"));
  17. }

代码示例来源:origin: apache/activemq

  1. if (jmsMessageConvertor != null) {
  2. if (doHandleReplyTo) {
  3. Destination replyTo = message.getJMSReplyTo();
  4. if (replyTo != null) {
  5. converted = jmsMessageConvertor.convert(message, processReplyToDestination(replyTo));

代码示例来源:origin: wildfly/wildfly

  1. setJMSReplyTo(foreign.getJMSReplyTo());
  2. setJMSDestination(foreign.getJMSDestination());
  3. setJMSDeliveryMode(foreign.getJMSDeliveryMode());

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void buildMessageWithStandardMessage() throws JMSException {
  3. Destination replyTo = new Destination() {};
  4. Message<String> result = MessageBuilder.withPayload("Response")
  5. .setHeader("foo", "bar")
  6. .setHeader(JmsHeaders.TYPE, "msg_type")
  7. .setHeader(JmsHeaders.REPLY_TO, replyTo)
  8. .build();
  9. Session session = mock(Session.class);
  10. given(session.createTextMessage("Response")).willReturn(new StubTextMessage("Response"));
  11. MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class);
  12. javax.jms.Message replyMessage = listener.buildMessage(session, result);
  13. verify(session).createTextMessage("Response");
  14. assertNotNull("reply should never be null", replyMessage);
  15. assertEquals("Response", ((TextMessage) replyMessage).getText());
  16. assertEquals("custom header not copied", "bar", replyMessage.getStringProperty("foo"));
  17. assertEquals("type header not copied", "msg_type", replyMessage.getJMSType());
  18. assertEquals("replyTo header not copied", replyTo, replyMessage.getJMSReplyTo());
  19. }

代码示例来源:origin: apache/activemq

  1. /**
  2. * Copies the standard JMS and user defined properties from the givem
  3. * message to the specified message
  4. *
  5. * @param fromMessage the message to take the properties from
  6. * @param toMessage the message to add the properties to
  7. * @throws JMSException
  8. */
  9. public static void copyProperties(Message fromMessage, Message toMessage) throws JMSException {
  10. toMessage.setJMSMessageID(fromMessage.getJMSMessageID());
  11. toMessage.setJMSCorrelationID(fromMessage.getJMSCorrelationID());
  12. toMessage.setJMSReplyTo(transformDestination(fromMessage.getJMSReplyTo()));
  13. toMessage.setJMSDestination(transformDestination(fromMessage.getJMSDestination()));
  14. toMessage.setJMSDeliveryMode(fromMessage.getJMSDeliveryMode());
  15. toMessage.setJMSRedelivered(fromMessage.getJMSRedelivered());
  16. toMessage.setJMSType(fromMessage.getJMSType());
  17. toMessage.setJMSExpiration(fromMessage.getJMSExpiration());
  18. toMessage.setJMSPriority(fromMessage.getJMSPriority());
  19. toMessage.setJMSTimestamp(fromMessage.getJMSTimestamp());
  20. Enumeration propertyNames = fromMessage.getPropertyNames();
  21. while (propertyNames.hasMoreElements()) {
  22. String name = propertyNames.nextElement().toString();
  23. Object obj = fromMessage.getObjectProperty(name);
  24. toMessage.setObjectProperty(name, obj);
  25. }
  26. }
  27. }

代码示例来源:origin: spring-projects/spring-integration

  1. public void onMessage(javax.jms.Message request, Session session) throws JMSException {
  2. String text = "priority=" + request.getJMSPriority();
  3. TextMessage reply = session.createTextMessage(text);
  4. MessageProducer producer = session.createProducer(request.getJMSReplyTo());
  5. reply.setJMSCorrelationID(request.getJMSMessageID());
  6. producer.send(reply);
  7. }
  8. }

代码示例来源:origin: spring-projects/spring-integration

  1. private void receiveAndSend(JmsTemplate template) {
  2. javax.jms.Message request = template.receive(requestQueue7);
  3. final javax.jms.Message jmsReply = request;
  4. try {
  5. template.send(request.getJMSReplyTo(), session -> jmsReply);
  6. }
  7. catch (JmsException | JMSException e) {
  8. }
  9. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void testJmsReplyToMappedFromHeader() throws JMSException {
  3. Destination replyTo = new Destination() {
  4. };
  5. Message<String> message = MessageBuilder.withPayload("test")
  6. .setHeader(JmsHeaders.REPLY_TO, replyTo).build();
  7. DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
  8. javax.jms.Message jmsMessage = new StubTextMessage();
  9. mapper.fromHeaders(message.getHeaders(), jmsMessage);
  10. assertNotNull(jmsMessage.getJMSReplyTo());
  11. assertSame(replyTo, jmsMessage.getJMSReplyTo());
  12. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void testJmsReplyToIgnoredIfIncorrectType() throws JMSException {
  3. Message<String> message = MessageBuilder.withPayload("test")
  4. .setHeader(JmsHeaders.REPLY_TO, "not-a-destination").build();
  5. DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
  6. javax.jms.Message jmsMessage = new StubTextMessage();
  7. mapper.fromHeaders(message.getHeaders(), jmsMessage);
  8. assertNull(jmsMessage.getJMSReplyTo());
  9. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void attemptToWriteDisallowedReplyToPropertyIsNotFatal() throws JMSException {
  3. Message<String> message = MessageBuilder.withPayload("test")
  4. .setHeader(JmsHeaders.REPLY_TO, new StubDestination())
  5. .setHeader("foo", "bar")
  6. .build();
  7. DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
  8. javax.jms.Message jmsMessage = new StubTextMessage() {
  9. @Override
  10. public void setJMSReplyTo(Destination replyTo) throws JMSException {
  11. throw new JMSException("illegal property");
  12. }
  13. };
  14. mapper.fromHeaders(message.getHeaders(), jmsMessage);
  15. assertNull(jmsMessage.getJMSReplyTo());
  16. assertNotNull(jmsMessage.getStringProperty("foo"));
  17. assertEquals("bar", jmsMessage.getStringProperty("foo"));
  18. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void testWithReply() throws Exception {
  3. QueueChannel replies = new QueueChannel();
  4. this.gateway1.setOutputChannel(replies);
  5. this.gateway1.start();
  6. this.gateway1.handleMessage(MessageBuilder.withPayload("foo")
  7. .setHeader(JmsHeaders.CORRELATION_ID, "baz")// make sure it's restored in case we're from an upstream gw
  8. .build());
  9. JmsTemplate template = new JmsTemplate(this.ccf);
  10. template.setReceiveTimeout(10000);
  11. final Message received = template.receive("asyncTest1");
  12. assertNotNull(received);
  13. template.send(received.getJMSReplyTo(), (MessageCreator) session -> {
  14. TextMessage textMessage = session.createTextMessage("bar");
  15. textMessage.setJMSCorrelationID(received.getJMSCorrelationID());
  16. return textMessage;
  17. });
  18. org.springframework.messaging.Message<?> reply = replies.receive(10000);
  19. assertNotNull(reply);
  20. assertEquals("bar", reply.getPayload());
  21. assertEquals("baz", reply.getHeaders().get(JmsHeaders.CORRELATION_ID));
  22. this.gateway1.stop();
  23. }

相关文章