SOA

What is Middleware

A software that helps disparate and distributed applications to collaborate with each otherSOA is the hottest middleware strategy till date.SOA Not a technology or product, more a design approach

Oracle SOA Suite


Provides “components” for designing, deploying, and managing “composite applications”.
Composites
enable you to easily assemble multiple technology components into one SOA composite application
Components
BPEL
OSB
Mediator
Human Workflow
Business rules
Adapters (FTP, DB, AQ, JMS, MQ, Apps, Siebel, PSFT…)
BAM
ODI

Introduction to WSDL

Web Services Description Language is an XML-based language used to define Web services and describe how to access them.







Working with a Mediator : Echo Pattern







This blog shows you how to work with a Mediator component in Oracle SOA Suite 11g.


This example uses the Echo pattern of the Mediator. An Echo is a simple "reply to the caller" pattern where the requestor immediately gets back a response.


This is typically used in use cases where a certain message has to be enriched, or some filtering to be done, etc.






Creating a Mediator


Create a new SOA Project, name it MediatorEchoPattern, select empty template













Defining the Schema


To begin with, define the message structures that will be used in the example.


In this tutorial, we will send in a message {firstName, lastName} and get back {fullName}. Based on this, define the xsd file


Rt click on xsd folder --> new --> All technologies --> xml schema --> name itEchoPatternSchema















Define the schema as shown below

















Creating the Mediator


Open composite.xml, drag and drop the Mediator component from the component palette to the components swimlane of the composite.xml


Name it EchoMediator, template as Define Interface Later. This interface will be created when we create a WebService and wire it to this, later.








This step creates an empty mediator.






Create a service endpoint


Mediator exists in the Components swimlane which is not directly exposed to the external world. In order to access it, we need to create a service endpoint through which external clients can access this component.


Here, we create a WebService with request and response types as defined in the schema earlier


To create a WebService, drag and drop the Web Service from the component palette to theExposed Services swimlane of the composite.xml


Name it EchoMediatorClient


In the WSDL url, select the second option Generate WSDL from Schema.


This will open a WSDL generation wizard where we need to select the Interface type and the message types for input and output. Select them as shown below
















This will create a WebService in the composite.xml


Now, wire the Webservice to the mediator as shown










Creating the Echo Pattern


Now that the wiring is done, the only thing remaining is to define the message flow


In this example which is an echo pattern, the request comes from the WebService, goes to the mediator, undergoes some transformation in the mediator, and finally is routed back to the WebService.


Hence, we need to create a routing rule in the mediator with an Echo Pattern






Double click on the mediator component in the composite.xml which will open a .mplan file which is the heart of the mediator component where all the operations of the mediator as defined in the other blog are to be defined.


For this tutorial which is more like a HelloWorld example, just a transformation file would be sufficient.






Click on the + icon of the Routing Rules --> Static Routing Rule --> Echo















This will add a Routing rule section in the file.


Here, we add a transformation file to transform the input message to the output message. Transformation file is mandatory for any type of mediator as that is the link that connects the input to the output within the mediator.


Click on the button at the end of the Transform Using, create a new mapper file and accept the default name

















This will open up a new wizard, where we can do all the transformations.


In this example, we need to concatenate the firstName & lastName, append hello to it, and assign it to the output


Concat function is available in the component palette at the right when you open the transformation file. Drag and drop this function to the middle section of the wizard,


then drag a line from each of the inputs to it, then double click on the concat function to addhello, and finally map it to the fullName at the right, as shown below
















Thats it, you're done!






Deploy this project. How to deploy is mentioned in this blog


EM URL : http://<host>:<adminPort>/em


Select the project under SOA-->soa_infra, click on test


















This is main logic behind Alarm



==========================================================================
SOA:JMS Queue Guide
==========================================================================

Java Messaging Service is an API that provides reliable, asynchronous communication between applications in a distributed computing environment. It enables a Java applications that share a messaging system to exchange messages and Simplifies application development by providing a standard interface for creating, sending, and receiving messages.

To Know about JMS Topic Please refer to: Basic JMS Demo using WebLogic Topic
What are major components of JMS system?

A). JMSServer: JMS server is an environment-related configuration entity that acts as management container for JMS queue and topic resources defined within JMS modules that are targeted to specific that JMS server.
B). JMS Modules: JMS modules contain configuration resources, such as standalone queue and topic destinations, distributed destinations, and connection factories. In WebLogic Server these Configurations can be seen inside “<DOMAIN_HOME>/config/jms” Directory.
C). JMS Client: A JMS is a JMS applications that either produce messages to destinations or consume messages from destinations.
D). JNDI : Java Naming And Directory interface,It is a Java API for a directory service that allows Java software clients to discover and look up data and objects via a name.
E). Persistent Store: It can be a UserDefined Persistent Store or a Default Persistent store. It is used for storing the Data (Messages).

Here we are going to see how we can configure WebLogic JMS Server, JMS Modules (Queue/ConnectionFactory) how to Target them and then How to test it using a Simpel Java Programs.

Step1). Start your WebLogic Server an Login to the AdminConsole.

Step2). Create a JMS Server…
Creating JMS Server
Creating JMS Server
Creating JMS Server-2
Creating JMS Server-2
Selecting JMS Server Store Type
Selecting JMS Server Store Type
Configuring JMS Store
Configuring JMS Store
Choosing JMS Store for JMSSErver
Choosing JMS Store for JMSSErver
Targeting to the JMSServer
Targeting to the JMSServer
Activating the JMS Server Configuration
Activating the JMS Server Configuration
Step3). Configuring JMS Module:
Creating JMS Module
Creating JMS Module
Entering JMS Module Name
Entering JMS Module Name
Targetting JMS Module
Targetting JMS Module
Finishing the Module Creation
Finishing the Module Creation
Step4). Creating Connection Factory:
Creating JMS Connection Factory
Creating JMS Connection Factory
Selecting JMS Module to be Created
Selecting JMS Module to be Created
Providing Name/JNDIName to Connection Factory
Providing Name/JNDIName to Connection Factory
Targeting the CnnectionFactory
Targeting the CnnectionFactory
Step5).Creating JMS Queue:
Selecting JMSQueue to be Created
Selecting JMSQueue to be Created
Queue Selection
Queue Selection
Assigning Name/JNDIName to Queue
Assigning Name/JNDIName to Queue
Creating SubDeployment
Creating SubDeployment
Assigning Name to the SubDeployment
Assigning Name to the SubDeployment
Targeting the JMS Queue
Targeting the JMS Queue
Activating the Final Changes
Activating the Final Changes

Step6). Now Write a Simple Java Program to send the Messages to this JMS Queue…like following:

“QueueSend.java”
01import java.io.*;
02import java.util.Hashtable;
03import javax.jms.JMSException;
04import javax.jms.Queue;
05import javax.jms.QueueConnection;
06import javax.jms.QueueConnectionFactory;
07import javax.jms.QueueSender;
08import javax.jms.QueueSession;
09import javax.jms.Session;
10import javax.jms.TextMessage;
11import javax.naming.Context;
12import javax.naming.InitialContext;
13import javax.naming.NamingException;
14
15public class QueueSend
16{
17public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
18public final static String JMS_FACTORY="QCF";
19public final static String QUEUE="TestQ";
20
21private QueueConnectionFactory qconFactory;
22private QueueConnection qcon;
23private QueueSession qsession;
24private QueueSender qsender;
25private Queue queue;
26private TextMessage msg;
27
28public void init(Context ctx, String queueName)
29throws NamingException, JMSException
30{
31qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
32qcon = qconFactory.createQueueConnection();
33qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
34queue = (Queue) ctx.lookup(queueName);
35qsender = qsession.createSender(queue);
36msg = qsession.createTextMessage();
37qcon.start();
38}
39
40public void send(String message) throws JMSException {
41msg.setText(message);
42qsender.send(msg);
43}
44
45public void close() throws JMSException {
46qsender.close();
47qsession.close();
48qcon.close();
49}
50
51public static void main(String[] args) throws Exception {
52if (args.length != 1) {
53System.out.println("Usage: java QueueSend WebLogicURL");
54return;
55}
56InitialContext ic = getInitialContext(args[0]);
57QueueSend qs = new QueueSend();
58qs.init(ic, QUEUE);
59readAndSend(qs);
60qs.close();
61}
62
63private static void readAndSend(QueueSend qs) throws IOException, JMSException
64{
65String line="Test Message Body with counter = ";
66BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
67boolean readFlag=true;
68System.out.println("\n\tStart Sending Messages (Enter QUIT to Stop):\n");
69while(readFlag)
70{
71System.out.print("&lt;Msg_Sender&gt; ");
72String msg=br.readLine();
73if(msg.equals("QUIT") || msg.equals("quit"))
74{
75qs.send(msg);
76System.exit(0);
77}
78qs.send(msg);
79System.out.println();
80}
81br.close();
82}
83
84private static InitialContext getInitialContext(String url) throws NamingException
85{
86Hashtable env = new Hashtable();
87env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
88env.put(Context.PROVIDER_URL, url);
89return new InitialContext(env);
90}
91}


Step7). Now run the “setWLSEnv.cmd” and then compile and Run the QueueSend program.

java QueueSend t3://localhost:7001

Step8). Now Login to AdminConsole to check that the Message is arrived in the JMS Queue or Not?

home—> Services–> Messaging–> JMS Modules–> MySystemModule–>MyQueue–> Monitoring–> MySystemModule –> MyQueue (Check the CheckBox)–> Show Messages(Click This Button)
Monitoring JMS Queue Message In AdminConsole
Monitoring JMS Queue Message In AdminConsole

Step9). Now write the following “QueueReceive.java” program to read JMS Messages from the JMS Queue.

“QueueReceive.java”
01import java.util.Hashtable;
02import javax.jms.*;
03import javax.naming.Context;
04import javax.naming.InitialContext;
05import javax.naming.NamingException;
06
07public class QueueReceive implements MessageListener
08{
09public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
10public final static String JMS_FACTORY="QCF";
11public final static String QUEUE="TestQ";
12private QueueConnectionFactory qconFactory;
13private QueueConnection qcon;
14private QueueSession qsession;
15private QueueReceiver qreceiver;
16private Queue queue;
17private boolean quit = false;
18
19public void onMessage(Message msg)
20{
21try {
22String msgText;
23if (msg instanceof TextMessage)
24{
25msgText = ((TextMessage)msg).getText();
26}
27else
28{
29msgText = msg.toString();
30}
31System.out.println("\n\t&lt;Msg_Receiver&gt; "+ msgText );
32if (msgText.equalsIgnoreCase("quit"))
33{
34synchronized(this)
35{
36quit = true;
37this.notifyAll(); // Notify main thread to quit
38}
39}
40}
41catch (JMSException jmse)
42{
43jmse.printStackTrace();
44}
45}
46public void init(Context ctx, String queueName) throws NamingException, JMSException
47{
48qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
49qcon = qconFactory.createQueueConnection();
50qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
51queue = (Queue) ctx.lookup(queueName);
52qreceiver = qsession.createReceiver(queue);
53qreceiver.setMessageListener(this);
54qcon.start();
55}
56
57public void close()throws JMSException
58{
59qreceiver.close();
60qsession.close();
61qcon.close();
62}
63
64public static void main(String[] args) throws Exception
65{
66if (args.length != 1)
67{
68System.out.println("Usage: java QueueReceive WebLogicURL");
69return;
70}
71InitialContext ic = getInitialContext(args[0]);
72QueueReceive qr = new QueueReceive();
73qr.init(ic, QUEUE);
74System.out.println("JMS Ready To Receive Messages (To quit, send a \"quit\" message from QueueSender.class).");
75// Wait until a "quit" message has been received.
76synchronized(qr)
77{
78while (! qr.quit)
79{
80try
81{
82qr.wait();
83}
84catch (InterruptedException ie)
85{}
86}
87}
88qr.close();
89}
90
91private static InitialContext getInitialContext(String url) throws NamingException
92{
93Hashtable env = new Hashtable();
94env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
95env.put(Context.PROVIDER_URL, url);
96return new InitialContext(env);
97}
98}


Step10). Now compile and run the QueueRecieve.java program to read the messages from WebLogic JMS Queue.

java QueueReceive t3://localhost:7001
Reference:http://middlewaremagic.com/weblogic/?p=1987


No comments:

Post a Comment