简体   繁体   English

JMSReplyTo,JMS代理的物理位置

[英]JMSReplyTo, physical location of the JMS broker

I'm confused about the nature of JMSReplyTo header. 我对JMSReplyTo标头的性质感到困惑。 It contains object of type javax.jms.Destination , typically being a logical handle to temporary queue created by the originator of the message. 它包含类型为javax.jms.Destination对象,通常是消息的发起者创建的临时队列的逻辑句柄。 Here is an experimental example of temporary queue creation and setting the JMSReplyTo header. 这是临时队列创建和设置JMSReplyTo标头的实验示例。

@Component("jmsbean")
public static class JmsBean {

    @Autowired
    @Qualifier("jmscf1")
    ConnectionFactory jmsServer1;

    @Autowired
    @Qualifier("jmscf2")
    ConnectionFactory jmsServer2;

    public String testJms(@Body String body) throws JMSException {

        Connection conn = jmsServer1.createConnection();
        conn.start();
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

        Connection conn2 = jmsServer2.createConnection();
        conn2.start();
        Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);

        TemporaryQueue tempQueue = session2.createTemporaryQueue();

        TextMessage message = session.createTextMessage();
        message.setJMSCorrelationID("tuomas");
        message.setJMSReplyTo(tempQueue);
        message.setJMSMessageID("tuomas");
        message.setText(body);

        Queue dest = session.createQueue("dest");
        MessageProducer producer = session.createProducer(dest);
        producer.send(message);

        session.close();
        conn.close();

        MessageConsumer consumer = session2.createConsumer(tempQueue);

        TextMessage reply = (TextMessage) consumer.receive();

        session2.close();
        conn2.close();

        return reply.getText();
    }
}

Now the message consumer could just pick the JMSReplyTo header from the Message object to get a reference to the temporary queue, and should send a response to this particular queue. 现在,消息使用者可以从Message对象中选择JMSReplyTo标头以获取对临时队列的引用,并应将响应发送到此特定队列。 And finally the originator receives it from that queue. 最后,发起者从该队列中接收到它。

But what actually links this Destination object to the physical location of the queue? 但是,实际上是什么将这个Destination对象链接到队列的物理位置的呢? I'm considering a special scenario, where the temporary queue resides in a remote server, in the internet, outside of the (request) consumer's domain. 我正在考虑一种特殊情况,其中临时队列位于(请求)使用者域之外的Internet上的远程服务器中。 There has to be some sort of IP address for the consumer to access the broker in the first place. 首先,消费者必须具有某种IP地址才能访问代理。 So is this mandated by the specification, or provider specific? 那么这是规范的要求还是提供者的特定要求?

How could I create ConnectionFactory , Connection and Session objects against the foreign remote broker to send the reply, if the only available information about the remote broker is in the JMSReplyTo header's Destination object? 如果有关远程代理的唯一可用信息位于JMSReplyTo标头的Destination对象中,那么如何针对外部远程代理创建ConnectionFactoryConnectionSession对象以发送答复? Does JMS specification guarantee all the information to initiate a session is available, and if so, how? JMS规范是否保证启动会话的所有信息都可用,如果可以,如何?

But what actually links this Destination object to the psychical location of the queue? 但是,实际上是什么将这个Destination对象链接到队列的心理位置呢?

The JMS specification does not define any link between a Destination and a physical location. JMS规范未定义Destination和物理位置之间的任何链接。 The Destination is essentially just a reference to an implementation-specific name where the message will be sent. Destination本质上只是对将消息发送到的实现特定名称的引用。

How could I create ConnectionFactory, Connection and Session objects against the foreign remote broker to send the reply, if the only available information about the remote broker is in the JMSReplyTo header's Destination object? 如果有关远程代理的唯一可用信息位于JMSReplyTo标头的Destination对象中,那么如何针对外部远程代理创建ConnectionFactory,Connection和Session对象以发送答复?

Unless the implementation you're using has extended its Destination to include such information (ie beyond the requirements of the JMS spec) then you won't be able to create a connection based on the the Destination . 除非您使用的实现将其Destination扩展为包括此类信息(即,超出JMS规范的要求),否则您将无法基于Destination创建连接。 I don't know of any implementation that has such an extension, and I would be surprised if any implementation did. 我不知道有这样的扩展的实现,如果有实现的话我会感到惊讶。

Does JMS specification guarantee all the information to initiate a session is available, and if so, how? JMS规范是否保证启动会话的所有信息都可用,如果可以,如何?

The JMS specification makes no such guarantees. JMS规范不提供此类保证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM