Using Message-Driven Bean and JMS Queue with ADF

EJB3.0 Message-Driven Bean asynchronously listens to JMS Queue/Topic and processes the messages from its clients.
In this article we will see how Message-Driven Bean listens to JMS Queue and process the message sent to Queue by a client, here I will be using ADF jspx page as our client.
This article will be split into two Sections. First Section, is for creating JMS Queue from WLS console, this is to help those who are not familiar in managing JMS from WLS console. Second Section, shows how to send a message from ADF client (jspx page) to JMS Queue and how to make Message-Driven Bean listen to the JMS Queue.

Section 1: Creating JMS Queue from WLS console

  • You need to have Integrated or Standalone WLS instance up and running.
  • FileSystem type Persistence Store has to be created to store JMS messages.
MessageDrivenBean-JMSQueue_CreatePersistenceStore1.JPG


MessageDrivenBean-JMSQueue_CreatePersistenceStore2.JPG


  • JMS Server is required to manage JMS Queues targeted at it.
MessageDrivenBean-JMSQueue_CreateJMSServer1.JPG


  • Use File Store create above as Persistence Store.
MessageDrivenBean-JMSQueue_CreateJMSServer2.JPG


  • Set 'DefaultServer' (for Integrated WLS) or 'AdminServer' (for Standalone WLS) as its Target Server.
MessageDrivenBean-JMSQueue_CreateJMSServer_TargetServer.JPG


  • JMS System Module is required to hold the queues.

MessageDrivenBean-JMSQueue_CreateJMSModule1.JPG


MessageDrivenBean-JMSQueue_CreateJMSModule2.JPG

  • Target JMS Module to server on which JMS Server is target.
MessageDrivenBean-JMSQueue_CreateJMSModule3.JPG
MessageDrivenBean-JMSQueue_CreateJMSModule3.JPG


MessageDrivenBean-JMSQueue_CreateJMSModule4.JPG

  • Check 'Would you like to add resources to this JMS system module' to include JMS queue to this newly created JMS Module.
MessageDrivenBean-JMSQueue_CreateJMSModule4.JPG


  • Create Sub Deployment and target it to JMS Server.

MessageDrivenBean-JMSQueue_SubDeployment1.JPG


MessageDrivenBean-JMSQueue_SubDeployment2.JPG


MessageDrivenBean-JMSQueue_SubDeployment3.JPG


  • Under Configurations tab click New button to create Connection Factories, Queues resources.
MessageDrivenBean-JMSQueue_CreateJMSModule_Config.JPG


  • Create JMS Connection Factory.
MessageDrivenBean-JMSQueue_ConnectionFactory1.JPG


MessageDrivenBean-JMSQueue_ConnectionFactory2.JPG


  • Now Target the Connection Factory to Sub Deployment created above.
MessageDrivenBean-JMSQueue_ConnectionFactory3.JPG


MessageDrivenBean-JMSQueue_ConnectionFactory4.JPG


  • Similarly create a Queue and target it to Sub Deployment.

MessageDrivenBean-JMSQueue_CreateJMSModule_Queue.JPG


MessageDrivenBean-JMSQueue_Queue1.JPG


MessageDrivenBean-JMSQueue_Queue2.JPG


  • With this we have configured WLS to handle JMS Queue.

Section 2: Send message from ADF client to JMS Queue and use Message-Driven Bean listen to the JMS Queue.

  • In a Custom Application Create Message-Driven Bean
MessageDrivenBean-JMSQueue_CreateMDBWizard.JPG


  • onMessage() of Message-Driven Bean is called by container when it receives message from a client.
  • onMessage() has to be modified accordingly to process the received message.

public void onMessage(Message message) {
  try{
    String sub= message.getStringProperty("subject");
    String mess= message.getStringProperty("message");
    System.out.println("Subject = " + sub);
    System.out.println("Message = " + mess);
   } catch(Exception e){
      e.printStackTrace();
  }
}

  • Create jspx page in View Controller project.
  • Drop two Input Texts from component palette to jspx page for Subject and Message.
  • Drop Command Button from component palette to jspx page.
MessageDrivenBean-JMSQueue_sendMessagePage.JPG


  • Bind Subject, Message input text to backing bean.
  • Create Action binding for send command button.
  • Add below code to send message to JMS queue.


QueueConnectionFactory connectionFactory;
try {
  connectionFactory = (QueueConnectionFactory)new InitialContext().lookup("jms.MDBConnectionFactory1");
  QueueConnection connection = connectionFactory.createQueueConnection();
  connection.start();
  QueueSession queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
  Queue queue = (Queue)new InitialContext().lookup("weblogic.wsee.DefaultQueue");
  QueueSender queueSender = queueSession.createSender(queue);
  Message message = queueSession.createMessage();
  message.setJMSType("logMessage");
  message.setLongProperty("time", System.currentTimeMillis());
  message.setStringProperty("subject", this.getIt1().getValue().toString());
  message.setStringProperty("message", this.getIt2().getValue().toString());
  queueSender.send(message);
  queueSession.close();
  connection.close();
} catch (Exception e) {
  e.printStackTrace();
}

  • Run jspx page
  • Give values to  Subject, Message and hit Send button.
  • onMessage() reads this message prints as Server Log.
MessageDrivenBean-JMSQueue_IntegratedWLSMsg.JPG

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Tips and Tricks from Oracle's JDeveloper & ADF QA

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today