Sunday, August 7, 2011

Oracle Service Bus JMS request reply with correlationId

http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/interopjms/transport.html


http://eelzinga.wordpress.com/2009/10/28/oracle-service-bus-jms-requestresponse-pattern/

So here we go:

create a project "MyRRJMS"

create a PS "RRPS",
Any XML Service,
protocol=JMS,
endpoint URL="jms://localhost:7001/weblogic.jms.XAConnectionFactory/RRPSRequest",
is response required=yes,
response pattern=JMSCorrelationID,
response URL="jms://localhost:7001/weblogic.jms.XAConnectionFactory/RRPSResponse"

the moment you activate the session, in the Server's JNDI tree you find 2 new objects with Binding Name:
RRPSRequest (weblogic.jms.common.DestinationImpl)
RRPSResponse (weblogic.jms.common.DestinationImpl)

Where do they come from? Look at
C:\Oracle2\Middleware\user_projects\domains\osb_domain\config\jms\xbusResources-jms.xml and there they are, all the JMS resources are declared in there.

You find out also that in
C:\Oracle2\Middleware\user_projects\domains\osb_domain\servers\AdminServer\tmp\_WL_user\_ALSB_1312707027768\6v4trg\META-INF

you have an exploded EAR with

application.xml =

<?xml version='1.0' encoding='UTF-8'?>
<jav:application xmlns:jav="http://java.sun.com/xml/ns/javaee">
  <jav:display-name>ProxyService MyRRJMS/RRPS</jav:display-name>
  <jav:module>
    <jav:ejb>ejb.jar</jav:ejb>
  </jav:module>
</jav:application>


and a weblogic-application.xml:

<?xml version='1.0' encoding='UTF-8'?>
<web:weblogic-application xmlns:web="http://xmlns.oracle.com/weblogic/weblogic-application">
  <web:ejb>
    <web:start-mdbs-with-application>false</web:start-mdbs-with-application>
  </web:ejb>
  <web:application-param>
    <web:param-name>service-ref</web:param-name>
    <web:param-value>ProxyService$MyRRJMS$RRPS</web:param-value>
  </web:application-param>
  <web:listener>
    <web:listener-class>com.bea.wli.sb.transports.jms.JmsEndPointAppListener</web:listener-class>
  </web:listener>
</web:weblogic-application>

and the ejb.jar contains:


weblogic-ejb-jar.xml:

<?xml version='1.0' encoding='UTF-8'?>
<web:weblogic-ejb-jar xmlns:web="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar">
  <web:weblogic-enterprise-bean>
    <web:ejb-name>RequestEJB-2434504941437409959-3df8b25b.131a331d3f9.-7fdb</web:ejb-name>
    <web:message-driven-descriptor>
      <web:pool>
        <web:max-beans-in-free-pool>1000</web:max-beans-in-free-pool>
        <web:initial-beans-in-free-pool>1</web:initial-beans-in-free-pool>
      </web:pool>
      <web:destination-jndi-name>RRPSRequest</web:destination-jndi-name>
      <web:provider-url>t3://localhost:7001</web:provider-url>
      <web:connection-factory-jndi-name>weblogic.jms.XAConnectionFactory</web:connection-factory-jndi-name>
    </web:message-driven-descriptor>
    <web:transaction-descriptor>
      <web:trans-timeout-seconds>600</web:trans-timeout-seconds>
    </web:transaction-descriptor>
    <web:resource-description>
      <web:res-ref-name>jms/ConnectionFactory</web:res-ref-name>
      <web:jndi-name>weblogic.jms.XAConnectionFactory</web:jndi-name>
    </web:resource-description>
    <web:resource-description>
      <web:res-ref-name>jms/QueueName</web:res-ref-name>
      <web:jndi-name>RRPSRequest</web:jndi-name>
    </web:resource-description>
  </web:weblogic-enterprise-bean>
  <web:weblogic-enterprise-bean>
    <web:ejb-name>ResponseEJB-2434504941437409959-3df8b25b.131a331d3f9.-7fdb</web:ejb-name>
    <web:message-driven-descriptor>
      <web:pool>
        <web:max-beans-in-free-pool>1000</web:max-beans-in-free-pool>
        <web:initial-beans-in-free-pool>1</web:initial-beans-in-free-pool>
      </web:pool>
      <web:destination-jndi-name>RRPSResponse</web:destination-jndi-name>
      <web:provider-url>t3://localhost:7001</web:provider-url>
      <web:connection-factory-jndi-name>weblogic.jms.XAConnectionFactory</web:connection-factory-jndi-name>
    </web:message-driven-descriptor>
    <web:transaction-descriptor>
      <web:trans-timeout-seconds>600</web:trans-timeout-seconds>
    </web:transaction-descriptor>
    <web:resource-description>
      <web:res-ref-name>jms/ConnectionFactory</web:res-ref-name>
      <web:jndi-name>weblogic.jms.XAConnectionFactory</web:jndi-name>
    </web:resource-description>
    <web:resource-description>
      <web:res-ref-name>jms/QueueName</web:res-ref-name>
      <web:jndi-name>RRPSResponse</web:jndi-name>
    </web:resource-description>
  </web:weblogic-enterprise-bean>
  <web:disable-warning>BEA-010001</web:disable-warning>
  <web:disable-warning>BEA-010054</web:disable-warning>
  <web:disable-warning>BEA-010200</web:disable-warning>
  <web:disable-warning>BEA-010202</web:disable-warning>
</web:weblogic-ejb-jar>


and ejb-jar.xml

<?xml version='1.0' encoding='UTF-8'?>
<jav:ejb-jar xmlns:jav="http://java.sun.com/xml/ns/javaee">
  <jav:display-name>BEA ALSB JMS Inbound Endpoint</jav:display-name>
  <jav:enterprise-beans>
    <jav:message-driven>
      <jav:display-name>BEA ALSB JMS Inbound Endpoint (Request)</jav:display-name>
      <jav:ejb-name>RequestEJB-2434504941437409959-3df8b25b.131a331d3f9.-7fdb</jav:ejb-name>
      <jav:ejb-class>com.bea.wli.sb.transports.jms.JmsInboundMDB</jav:ejb-class>
      <jav:transaction-type>Container</jav:transaction-type>
      <jav:message-destination-type>javax.jms.Queue</jav:message-destination-type>
      <jav:env-entry>
        <jav:env-entry-name>service-ref</jav:env-entry-name>
        <jav:env-entry-type>java.lang.String</jav:env-entry-type>
        <jav:env-entry-value>ProxyService$MyRRJMS$RRPS</jav:env-entry-value>
      </jav:env-entry>
      <jav:env-entry>
        <jav:env-entry-name>XA-supported</jav:env-entry-name>
        <jav:env-entry-type>java.lang.Boolean</jav:env-entry-type>
        <jav:env-entry-value>true</jav:env-entry-value>
      </jav:env-entry>
      <jav:env-entry>
        <jav:env-entry-name>checksum</jav:env-entry-name>
        <jav:env-entry-type>java.lang.Integer</jav:env-entry-type>
        <jav:env-entry-value>-319661414</jav:env-entry-value>
      </jav:env-entry>
    </jav:message-driven>
    <jav:message-driven>
      <jav:description>BEA ALSB JMS Inbound Endpoint (Response) (AdminServer)</jav:description>
      <jav:ejb-name>ResponseEJB-2434504941437409959-3df8b25b.131a331d3f9.-7fdb</jav:ejb-name>
      <jav:ejb-class>com.bea.wli.sb.transports.jms.JmsAsyncResponseMDB</jav:ejb-class>
      <jav:transaction-type>Container</jav:transaction-type>
      <jav:message-destination-type>javax.jms.Queue</jav:message-destination-type>
      <jav:activation-config>
        <jav:activation-config-property>
          <jav:activation-config-property-name>messageSelector</jav:activation-config-property-name>
          <jav:activation-config-property-value>JMSCorrelationID LIKE 'ID:424541534594cf52%'</jav:activation-config-property-value>
        </jav:activation-config-property>
      </jav:activation-config>
      <jav:env-entry>
        <jav:env-entry-name>service-ref</jav:env-entry-name>
        <jav:env-entry-type>java.lang.String</jav:env-entry-type>
        <jav:env-entry-value>ProxyService$MyRRJMS$RRPS</jav:env-entry-value>
      </jav:env-entry>
      <jav:env-entry>
        <jav:env-entry-name>XA-supported</jav:env-entry-name>
        <jav:env-entry-type>java.lang.Boolean</jav:env-entry-type>
        <jav:env-entry-value>true</jav:env-entry-value>
      </jav:env-entry>
    </jav:message-driven>
  </jav:enterprise-beans>
  <jav:assembly-descriptor>
    <jav:container-transaction>
      <jav:method>
        <jav:ejb-name>RequestEJB-2434504941437409959-3df8b25b.131a331d3f9.-7fdb</jav:ejb-name>
        <jav:method-name>*</jav:method-name>
      </jav:method>
      <jav:trans-attribute>Required</jav:trans-attribute>
    </jav:container-transaction>
    <jav:container-transaction>
      <jav:method>
        <jav:ejb-name>ResponseEJB-2434504941437409959-3df8b25b.131a331d3f9.-7fdb</jav:ejb-name>
        <jav:method-name>*</jav:method-name>
      </jav:method>
      <jav:trans-attribute>Required</jav:trans-attribute>
    </jav:container-transaction>
  </jav:assembly-descriptor>
</jav:ejb-jar>


To inject messages in the Request queue, write a Business Service "writeToRequestQueue"

Any XML Service
protocol=JMS
Endpoint URI=jms://localhost:7001/weblogic.jms.XAConnectionFactory/RRPSRequest
No response

To read messages from the Response queue, write a Proxy Service "readFromResponseQueue"

Any XML Service
protocol=JMS
Endpoint URI=jms://localhost:7001/weblogic.jms.XAConnectionFactory/RRPSResponse
No response
in its Message Flow, add a pipeline, stage, add action "log" expression "$body"

Everything is operational: when you writeToRequestQueue, the message is consumed by the RRPS, put to the ResponseQueue where it is consumed by readFromResponseQueue.

So what is the big deal, we could have achieved the same without all this circus of Request/Reply and correlationId. Where is the correlationId by the way?
We will discover all this in the next installment.

No comments: