Creating a JMS Topic with
Durable Subscriber in weblogic:
JMS Topic
Topic is a distribution mechanism for publishing messages that are delivered to multiple subscribers. Multiple consumers can get the message .There is a timing dependency between publishers and subscribers. The publisher has to create a subscription in order for clients to be able to subscribe. The subscriber has to remain continuously active to receive messages, unless it has established a durable subscription. In that case, messages published while the subscriber is not connected will be redistributed whenever it reconnects.
JMS Topic
Topic is a distribution mechanism for publishing messages that are delivered to multiple subscribers. Multiple consumers can get the message .There is a timing dependency between publishers and subscribers. The publisher has to create a subscription in order for clients to be able to subscribe. The subscriber has to remain continuously active to receive messages, unless it has established a durable subscription. In that case, messages published while the subscriber is not connected will be redistributed whenever it reconnects.
There are few steps involved in creating and using JMS Topic.
1.
Creating JMS Topic
2.
Creating a Connection factory
3.
Creating a Durable Subscriber
4.
Creating an Outbound connection
pool in the JMS Adapter
Non-Durable Subscription – In publish/subscribe messaging model of JMS, messages are retained in the Topic as long as either they are delivered to all the current/active subscribers or they are expired. This means that subscribers who have disconnected and are not listening actively, would not receive any messages published on the topic during the time they remain disconnected. Thus, in non-durable subscription any message published on the topic, when the subscriber was inactive would be lost.
Durable Subscription – There is an option in publish/subscribe model for subscribers to receive the messages that were published on the topic when they were disconnected or inactive. This is known as durable subscription. When the subscriber is inactive, messages are persisted and delivered when the subscriber becomes active. Thus, durable subscription allows subscribers to dis-connect, re-connect again and fetch all the messages published on the topic when they were disconnected.
Non-Durable Subscription – In publish/subscribe messaging model of JMS, messages are retained in the Topic as long as either they are delivered to all the current/active subscribers or they are expired. This means that subscribers who have disconnected and are not listening actively, would not receive any messages published on the topic during the time they remain disconnected. Thus, in non-durable subscription any message published on the topic, when the subscriber was inactive would be lost.
Durable Subscription – There is an option in publish/subscribe model for subscribers to receive the messages that were published on the topic when they were disconnected or inactive. This is known as durable subscription. When the subscriber is inactive, messages are persisted and delivered when the subscriber becomes active. Thus, durable subscription allows subscribers to dis-connect, re-connect again and fetch all the messages published on the topic when they were disconnected.
Prerequisites:
1.
Weblogicserver ,Oracle SOA
Suite 11g and Oracle JDeveloper should be installed and configured.
2.
Weblogic Admin Server should be
up and running.
3.
If separate node manager is
created for SOA, it should be up and running.
4.
Oracle JDeveloper with SOA
extension.
Creating JMS Topic:
1.
Login to weblogic console http://<host>:<port>/console
2.
In the domain structure , go to
JMS Modules
3.
Click on JMS Modules and in the
Right pane Select the Module required.
By default, SOAJMSModule will
be available , In case for any user defined module create one using New button
under JMS Module.
4.
Now under SOAJMSModule we are
going to create a new resource. We can create any one of the below resources
for JMS .
i.
Connection Factory
ii.
Queue
iii.
Topic
iv.
Distributed Queue
v.
Distributed Topic
vi.
Foreign Server
vii.
Quota
viii.
Destination Sort Key
ix.
JMS Template
x.
SAF Imported Destinations
6.
In the next page , choose the type of resource to be
created.
8.
Now JMS Destination properties has to be provided. In the properties
fill the following
Name : SampleTopicPOC
JNDI Name: jms/SampleTopicPOC
Template : Leave Default
9.
Click Next to Click Next to choose the Subdeployment. If a
new / User defined Subdeployment should be selected in the drop down list. If
needed to be created use the Create a
New Subdeploymentbutton to create
one or leave the default subdeployment(SOASubDeployment).
Creating a Connection Factory:
1.
Now a connection factory has to
be created. For that click New
button in the JMS Resources Creation
page.
2.
In the Resource selection page
select Connection Factory and click Next.
3.
In the Connection properties
provide the following details
Name :SampleCFPOC
JNDI Name: jms/SampleCFPOC
Rest others use the
default ones and click Next.
4.
Now select the target to be deployed. Since only Admin
server is there it has been selected by default. If there are more targets (ie.
Individual node managed servers created / available) then select the
appropriate target and click Finish.
5.
Once done we will get a success
message.
6.
After this we could be able to
see the Topic and Connection Factory in the JMS Modues.
Creating a Durable
Subscriber for a Topic:
5.
We will get a success message
in the next page. We could see the a subscriber created.
Creating an Outbound
connection pool in the JMS Adapter (With
Durable Subscriber)
1.
In the deployments page click on JMS
Adapter.
5.
Now save the deployment Plan. If it is the first
time deployment provide the respective plane file to be updated . By default
all the deployments will be deployed to Plan.xml file. Choose the correct plan
file and click Ok .
6.
We will get a success message
after the deployment.
7.
Now click Configuration ->Outbound Connection Pools and expand the oracle.tip.adapter.jms.IJmsConnectionFactory.
The created Connection pool will be available with name eis/jms/SampleTopicDS.
8.
Click on that and provide the
appropriate connection factory name in the Connection
Factory Location column with the connection factory JNDI name (jms/SampleCFPOC) and press enter key in keyboard.
As we are creating the JMS
Topic with Durable Subscriber, In Factory
Properties type “ClientID=Sample”
, press Enter key from keyboard . Then click on IsTopic and change the value to “true” press Enter key from
keyboard and click Save on the
page.
10.
Now the adapter should be
updated with the modifications. So Click Deployments
and select JMSAdapter and click Update.
Note: Click Lock and Edit button in the left pane
as we are going to update the details to weblogic.Once done use Release Configuration.
11.
Select Update this application option and click Next.
12.
Click Finish in the next page.
13. After this we will get success message.
Now we are ready to create
JMS related interfaces either using JMS Topic.
JMS Adapter Types:
There are two different ways to use the JMS Topic for exchanging
messages.
1.
Produce and Consume way of
exchanging messages
2.
Request-Reply way of exchanging
messages.
A. Produce/Consume Type:
JMS Producer
1.
In the left pane in the
Applicaton Navigator Drop Down select the application under which the project
should be created.
2.
Right click on the Application
and Select New Project.
3.
In the next window on the left
pane under Categories select Projects and in Right pane under Items select SOA Project.
4.
In Name Your Project section, provide Name (TopicSampleProducer).
For Directory choose
the path where the project files should be created.
In the Project Technologies
section select SOA and move it to Selected section using the Right Arrow and click Next.
5.
In the next page select the
template. Choose Empty Composite and
click Finish.
Using the above steps create a project for JMS Producer.
Note:
Xsd used for the message creation.
<?xml version=
'1.0' encoding= 'UTF-8' ?>
<xs:schema
attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.Sample.org/2001/XMLSchema">
<xs:element name="Message">
<xs:complexType>
<xs:sequence>
<xs:element
type="xs:string" name="ClientID"/>
<xs:element
type="xs:string" name="singleString"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Producer
1.
After the project creation we
could see the composite.xml
2.
In the External References
section, drag and drop JMS Adapter.
3.
In the JMS adapter creation
wizard click Next.
4.
Provide the Adapter Service name and click Next.
5.
Now select the JMS Provider
.Since the one we are using is the Oracle
Weblogic server and its JMS select Oracle
Enterprise Messaging Services (OEMS) and in the drop down select Oracle Weblogic JMS.
6.
In the next page we have to
create or choose the service connection of the application server where JMS is
running. In the flow either select already existing one or create new
application server using the steps in the Creating
an Application server for Adapter or Deployment configuration section of
the Using JMS
Queue for message exchange in SOA 11G blog.Once
application server is created we will be back to the JMS adapter configuration
wizard with the connection selected in dropdown list. Select required
Application server connection and click Next.
7.
Click option Define from operation and schema (specified
later) as we are going to define the schema later and click Next.
8.
In the operation section,
select Produce Message option and
click Next.
9.
In the next section we have to
provide the Produce Operation Paramters.
10.
For selecting the message click
Browse Button and in the options
listed select the destination Topic.
11.
After the topic selection
provide the JNDI name what has been configured in console. In our case it is eis/jms/SampleTopicPOC. If needed
change the default options for the Priority ,Time to live, Delivery Mode,
Message Type and click Next.
12.
Now select the schema for the
message to be produced. Use the search icon.
13.
Since we don’t have the schema
file we will import it from the file system.For this in the Type chooser select
the option to Import Schema file.
14.
In the Import Schema File click
on the select icon to choose the file.
15.
In the SOA Resource Browser
select the File System in the dropdown and choose the file and select ok.
16.
In the next step leave the
default option and click OK.
17.
In Localize files option uncheck
the Maintain original directory structure for imported files and click OK.
18.
Now in the type chooser select
the Message Type and click OK.
19.
Now the xsd file would be
chosen . Click OK.
20.
Click Next and Finish to complete the
Adapter creation.
21.
Now we could be able to see
wsdl and jca files created for the Adapter.
22.
In the composite.xml file drag
a mediator component into the
Components Section.
23.
In the next section provide the
name and select the template for the Mediator.
·
Name: MessageProducer
·
Template: One-Way Interface
·
Check the option Create Composite Service with SOAP Bindings
·
Click OK
24.
In the Input section click on
the search icon to choose the message type of the mediator.
25.
From the type choose select the
element.
26.
Now Input will have the type
selected from the xsd file.
27.
Now the Mediator with SOAP
Bindings is created in the composite.
28.
Now wire the Mediator with
JMSAdapter in the external refereneces
section.
29.
Now in the resulting
combination double click on the mediator.
30.
We could see the mplan file
displayed.
31.
Now create a mapping from input
to JMS adapter by clicking the transform in the Transform Using section of the
Routing Rules.
32.
Leave default options for
creating the mapping file or name it and click ok.
33.
In the resulting mapping file
map the source to target for ClientID and singleString elements.
34.
Click Save All.
Now deploy the interface. Follow the steps in the Steps for Deploying a SOA process section of the Using JMS Queue for message exchange in SOA 11G blog.
Testing:
1.
In the EM .Click the interface
deployed which is under <Domain> -> SOA -> soa-infra ->
<Partition> and click Test.
2.
Pass the values to test and
click Test Web Service.
3.
In the resulting page click
Launch Flow Trace.
4.
In the popup the flow will be
shown.
5.
Now let us check whether the
messages are in the Topic’s Durable Subscriber.For this login to Weblogic
console and click <Domain>-> Services -> Messaging -> JMS
Modules and in the right side of JMS
Modules click on SOAJMSModule or respective module where the Topic and its Subscriber
is created.
6.
Click the Topic which has the
Durable Subscriber.
7.
In Monitoring tab and Durable
Subscribers check the Durable Subscriber and click Show Messages.
8.
In the next page we could see
the Message with id created with timestamp.
9.
Click on the message and we
could see the message published which we have passed as input from the Producer
interface.
Consumer:
1.
Create a SOA Project using the
same steps which has been shown for creating a Producer using the following
details.
Project Name:
TopicSampleConsumer
2.
We could see the Composite file
created.
3.
Now drag and drop the JMS
Adapter in the Exposed Services section.
4.
In the welcome screen click
Next.
5.
In the Service Name provide a
name and click Next.
6.
In the JMS Provider section
select the Oracle Enterprise Messaging service and in the drop down select
Oracle Weblogic JMS.Click Next.
7.
Now in the service connection
wizard either select the application server which already got created or create
a new one.For creating new Application server follow the steps in the Creating an Application server for Adapter
or Deployment configurationsection.Once done select the application server.
After selecting the appropriate server click Next.
8.
In the Adapter Interface
section select the Define from operation
and schema (specified later) and click Next.
9.
In the operation type select
Consume Message and click Next.
10.
In the next page select
Operation Parameters.
11.
From the above page click
Browse to select the topic.
12.
Provide the JNDI Name (eis/jms/SampleTopicPOC) and
i n the Durable Subscriber ID type
Sample.If required configure the Message type, Messgae selector ( kind of
condition to pick the messages which satifies the condition).Click Next .
13.
Now in the messages section
select the schema .Click the search button to search and select the schema
file.
14.
Since we don’t have the schema
file we will import it from the file system. Use the steps described in the
adapter creation of the Producer (Step 12 to Step 19). From the Type chooser
select the type and click OK.
15.
Click Next.
16.
Click Finish.
17.
In the composite drag and drop
a BPEL process into the Component Section.
18.
Provide the name, Template with
One way BPEL process , Uncheck the Expose as a SOAP Service and Click OK.
19.
Now wire the JMS adapter with BPEL
process.
20.
Once wired Double click on the
BPEL component.
21.
In the resulting bpel file do
the following
·
Right click on the wire between
receiveInput and bpelprocessconsumer partner link , select Delete and Click Yes
in the resulting popup.
·
Now delete the
bpelprocessconsumer partner link and click Yes in the resulting popups.
·
Now in the scope of the bpel
click on Variables and delete the default variable created and click OK.
·
Now wire receiveInput and
JMSConsumer partner link and in the resulting popup provide the name and click
on Auto Create Variable in Variable section, leave default value and click OK.
·
Click OK.
·
Again create a new variable
with the type that was used in JMS adapter for the output.
·
Now the variables section will
look like the below one.
22.
Now drag and drop an assign
activity next to receiveInput section. Name it and double click on the assign
activity.
23.
Map the input to output
variables.
24.
Now click Save all.
25.
Deploy the interface as done
for the producer.
Testing:
1.
From EM if the input is given
to the Producer interface it will be consumed by the consumer interface which
will look like the below one when we see the flow trace of the consumer.
2.
Now click the consumer bpel
process and check the output payload.
B.
JMS Request Reply
Note: XSD used is same
as the Producer/Consumer Type.
1.
Create the new project for the
request reply process using the following steps.
2.
In the Jdeveloper Application
Navigator Select the application under which the project should be created and
click New Project.
4.
In the Name your Project
section provide the Name and Select the folder structure where the project
files should be created and in the Project Technologies section select SOA and
move to the Selected section using the right arrow mark and click Next.
5.
In the next section select the
composite template. For now select Empty composite and click Finish.
7.
Drag and drop JMS Adapter from
the Services section of the Component Palatte into the External References
pane.
10.
In the JMS Provider section
select the Oracle Enterprise Messaging service and in the drop down select
Oracle Weblogic JMS.
11.
Click Next
12.
Now in the service connection
wizard either select the application server which already got created or create
a new one.For creating new Application server follow the steps in the Creating an Application server for Adapter
or Deployment configurationsection.Once done select the application server.
14.
In the Adapter Interface
section select the Define from operation
and schema (specified later)and click Next.
15.
In the operation section select
Request/Reply and Operation Name select
Asynchronous and click Next.
22.
In the messages section select
the message type from the xsd file for both request and reply using the search
icon.
25.
Now drag and drop BPEL Process
in the Service components of the Component Palatteto the Components section.
26.
Provide the Name for the BPEL
process , select Asynchronous BPEL Process in the Template , Check Expose as a
SOAP service option and click OK.
28.
Now double click on the
BPELReqReply BPEL component . We could see the .bpel file opened with default
receive callback section.
29.
Now drag and drop Invoke
activity from Component Palatte -> BPEL Constructs -> Web Service after
the receiveInput.
30.
Wire the Invoke activity to JMS
Adapter JMSReqReply.By default a popup for Editing the invoke appears.
31.
In the General tab of the Edit
Invoke popup provide the name and create new variable by clicking the Green
plus icon in the Variables -> Input section.
34.
Now drag and drop Receive
activity from the Component Palatte -> Web Services -> BPEL Constructs
after the Invoke activity.
36.
In the Edit receive popup
provide the Name in General tab and create new variable by clicking the Green
plus icon in the Name Variable.
39.
Now drag and drop Assign
activity from Component Palatte -> BPEL Constructs -> Activities ->
Assign in between receiveInput and Invoke activity.
41.
In copy rules section of the
Assign map
From : Variables ->
Process -> Variables ->inputVariable -> Payload ->client:process
->client:inputString
To: Variables-> Process
->Variables ->InvokeRequest_Request_Input_Variable->singleString ->
ns2:singleString
Click OK.
44.
Double Click on assign activity
and map the following.
From : Variables ->
Process->Variables->ReceiveReply_Reply_InputVariable->singleString->ns2:singleString.
46.
Click Save all.
47.
Now deploy the process .
Testing:
1.
Login to emhttp://<host/ip>:<port>/em
2.
<Domain> -> SOA
->soa-infra -><Partition> ->TopicSampleRequestReply process
8.
Now in the flow click callback
client.
9.
In the outcoming popup we could
see the output with the message we have given as input.
good deal !!
ReplyDeleteNice
ReplyDeleteIt 's an amazing and awsome blog Thanks for sharing
ReplyDeleteOracle SOA Online Training