(WID/WPS) Sending/Receiving Message using JMS Export



Following code shows how to use JMS export binding to send message to the mediation module & get response back from the same.


Flow is like:
JMS Export ->> Mediation Module ->> Web Service Import (Can be any service provider)


Code Snippet for JMS Client :
try{
String icf = "com.ibm.websphere.naming.WsnInitialContextFactory";


//the Provider URL
String url = "iiop://localhost:2809";


//The Queue Connection Factory used to connect to the bus
String sampleQCF = "jms/sampleQCF";


//The Queue used to send requests to the mediation module
String sampleSendQueue = "jms/profileServiceExportIn";


//The Queue used to receive responses from the mediation module
String sampleReceiveQueue = "jms/profileServiceExportOut";


//The XML representation of a Profile which is the Business Object required by the add operation on the ProfileService Interface.
String message = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
message += "<profile xmlns:ns2=\"http://BookOrderResources\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"ns2:Profile\">";
message += "<name>"+request.getParameter("name")+"</name>";
message += "<address>";
message += "<street>"+request.getParameter("street")+"</street>";
message += "<city>"+request.getParameter("city")+"</city>";
message += "<country>"+request.getParameter("country")+"</country>";
message += "</address>";
message += "<creditCardNum>"+request.getParameter("creditCardNum")+"</creditCardNum>";
message += "<lastUpdate>2006-02-16</lastUpdate>";
message +=  "</profile>";


java.util.Hashtable env = new java.util.Hashtable();
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, icf);
env.put(javax.naming.Context.PROVIDER_URL, url);
javax.naming.Context ctx = new javax.naming.directory.InitialDirContext(env);


//Lookup the ConnectionFactory
javax.jms.ConnectionFactory factory = (javax.jms.ConnectionFactory)ctx.lookup(sampleQCF);


//Create a Connection
javax.jms.Connection connection = factory.createConnection();


//Start the Connection
connection.start();


//Create a Session
javax.jms.Session jmsSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);


//Lookup the send Destination
javax.jms.Destination sendQueue = (javax.jms.Destination) ctx.lookup(sampleSendQueue);


//Create a MessageProducer
javax.jms.MessageProducer producer = jmsSession.createProducer(sendQueue);


//Create the TextMessage that will hold out profile as text
javax.jms.TextMessage sendMessage = jmsSession.createTextMessage();


//Set the content of the message to be the XML defined Profile
sendMessage.setText(message);


//Set the operation to call on the ProfileService interface to be add
sendMessage.setStringProperty("TargetFunctionName", "add");


//Send the message
producer.send(sendMessage);


//Lookup the receive Destination
javax.jms.Destination receiveQueue = (javax.jms.Destination) ctx.lookup(sampleReceiveQueue);


//Create a MessageConsumer
javax.jms.MessageConsumer consumer = jmsSession.createConsumer(receiveQueue);


//Wait 15 seconds to receieve the response
javax.jms.TextMessage receiveMessage = (javax.jms.TextMessage) consumer.receive(15000);


if (receiveMessage != null) {
System.out.println(receiveMessage.getText());
}


//Close the Connection
connection.close();
}
catch (Exception e) {
e.printStackTrace();
}


Server run time configuration:

We need to create both the queues & QCF along with activation specification so that the module can register the input queue with its message listener as follows:

  • Click Resources → JMS Providers → Default messaging.
  • Under Activation Specifications, click JMS activation specification.
  • Click New to create an activation specification 
    • Set the name field to sampleAS.
    • Set the JNDI name field to jms/sampleAS.
    • Select the destination type as Queue.
    • Set the Destination JNDI name to jms/profileServiceExportIn.
    • Select the SCA.APPLICATION.esbCell.Bus bus from the Bus name menu.


Following are the screen shots for business object & interface:


Business objects used in ProfileService interface


 ProfileService interface
Attached PI


1 comment:

  1. Инстраграмм остается самой популярной на данный момент площадкой для продвижения своего бизнеса. Но, как показывает практика, люди гораздо чаще подписываются на профили в которых уже достаточное количество подписчиков. Если заниматься продвижение своими силами, потратить на это вы можете очень немало времени, поэтому гораздо лучше обратиться к специалистам из Krutiminst.ru по ссылке https://erickaska09876.atualblog.com/18624405/how-to-get-instagram-followers-speedy

    ReplyDelete