Jede Anfrage folgt dem folgenden allgemeinen Ablauf:
- Erstellen Sie einen JNDI InitialContext mit
Code: Select all
com.ibm.websphere.naming.WsnInitialContextFactory - Suchen Sie die JMS ConnectionFactory über JNDI
(zum Beispiel: jms/ABCD) - Suchen Sie die Anfragewarteschlange und Antwortwarteschlange über JNDI
- Erstellen Sie eine JMS-Verbindung aus der ConnectionFactory
- Erstellen Sie eine nicht-transaktionierte JMS-Sitzung mit AUTO_ACKNOWLEDGE
- Starten Sie die Verbindung
- Erstellen Sie eine MessageProducer
- Erstellen und senden Sie die MQ-Anforderungsnachricht (CIH-Format)
- Schließen Sie alle JMS- und JNDI-Ressourcen im final-Block
Ebenso haben wir die Sitzungsverbindung für den Verbraucher erstellt.
Code: Select all
context = new InitialContext(environment);
ConnectionFactory connectionFactory =
(ConnectionFactory) context.lookup("jms/ABCD");
Destination requestQueue =
(Destination) context.lookup(requestQueueName);
Destination replyQueue =
(Destination) context.lookup(replyToQueueName);
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
producer = session.createProducer(requestQueue);
producer.send(message);
Code: Select all
javax.jms.JMSException: Failed to create connection
at com.ibm.ejs.jms.JMSCMUtils.mapToJMSException(JMSCMUtils.java:140)
at com.ibm.ejs.jms.JMSConnectionFactoryHandle.createConnection(JMSConnectionFactoryHandle.java:277)
at com.hdb.jms.JMSServiceSender.doCicsRequestReplySend(JMSServiceSender.java:84)
at com.hdb.jms.JMSService.CicsRequestReply(JMSService.java:30)
- laden
Code: Select all
finally {
if (producer != null) {
producer.close();
}
if (session != null) {
session.close();
}
if (context != null) {
context.close();
}
if (connection != null) {
connection.close();
}
}
Mobile version