JMSClient(在某些情况下也是生产者)是否会收到它自己发送的消息?
答案 0 :(得分:2)
我得到了答案..有一个noLocal标志,可以设置为不接收来自同一连接的消息
答案 1 :(得分:1)
肯定是的,如果它在一个目的地上有一个监听器,它也会产生消息。
答案 2 :(得分:0)
正如您在下面的示例中所看到的,客户端既可以是生产者,也可以是消费者。这取决于你如何设置它。通常,如果您正在执行异步消息传递,则客户端可以是使用者或生产者。如果您正在进行请求/回复,那么它会同时执行这两项操作,您可以使用correlationID或messageID来跟踪您的请求和回复。以下示例用于异步通信。
myConnFactory = new com.sun.messaging.ConnectionFactory();
Connection myConn = myConnFactory.createConnection();
//Create a session within the connection.
Session mySess = myConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
myQueue = new com.sun.messaging.Queue("world");
//Create a message producer.
MessageProducer myMsgProducer = mySess.createProducer(myQueue);
//Create a message consumer. (Use if going to read from the queue)
MessageConsumer myMsgConsumer = mySess.createConsumer(myQueue);
//Start the Connection
myConn.start();
//Create and send a message to the queue.
TextMessage myTextMsg = mySess.createTextMessage();
myTextMsg.setText("Hello World");
System.out.println("Sending Message: " + myTextMsg.getText());
myMsgProducer.send(myTextMsg);
// The rest of the code is for reading from a queue - optional
//Receive a message from the queue.
Message msg = myMsgConsumer.receive();
//Retreive the contents of the message.
if (msg instanceof TextMessage) {
TextMessage txtMsg = (TextMessage) msg;
System.out.println("Read Message: " + txtMsg.getText());
}