'What is Queue in JMS
I have a task. In parameters there are queue and message. I must send message to a queue. And I don't know where in is this queue is my queue. I think that it is Destination queue? Thanks a lot.
public class Producer {
public static void main(String[] args) {
try {
// Получает контекст JNDI
Context jndiContext = new InitialContext();
// Выполняет поиск администрируемых объектов
ConnectionFactory connectionFactory = (ConnectionFactory) jndiContext.lookup("jms/javaee7/ConnectionFactory" );
Destination queue = (Destination) jndiContext.lookup("jms/javaee7/Queue");
//Создает необходимые артефакты для соединения с очередью
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
// Отправляет текстовое сообщение в очередь
TextMessage message = session.createTextMessage("Сообщение отправлено " + new Date());
producer.send(message);
connection.close();
} catch (NamingException | JMSException e) {
e.printStackTrace();
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
