I wrote some content about JMS in my previous blog. Later I thought that the content of that blog was not enough to elaborate on JMS, so this blog will continue to improve JMS.
Configure the JMS feature of jmsweblogic server in the WebLogic Server Environment
- Weblogic server implements the JMS service provider (Service Provider) in accordance with the JMS 1.0.2 specification)
- WebLogic Server JMS support:
- Point-to-point and publish/subscribe Domains
- Ensure message distribution
- Message distribution of transactions
- Reliable subscription Mechanism
- Server-side consumer session pool
- Multicast
- Cluster
JMS Server
- In WebLogic Server, message service is implemented through the JMS server.
- The JMS server is responsible for interpreting and distributing messages.
Configure WebLogic Server JMS
- The process of configuring WebLogic JMS consists of three steps:
- JMS Server
- Queue and/or topic
- Connection Factory (optional)
Write a simple JMS Client
- Configure JMS in WebLogic Server
- Write a simple JMS Client
- Compile a simple JMS producer
- Write a simple JMS consumer
- Send message
- Receive messages
- JMS transaction
JMS architecture: Connection)
JMS architecture: Send messages
Five steps:
Let's continue to look at the following three steps in the pipeline to connect:
Step 1 -- query the connection Factory)
- Connection Factory:
- Is a lightweight object stored in JNDI.
- Create a new connection to the target
- There are two connection types:
- Queueconnectionfactory
- Topicconnectionfactory
QueueConentionFactory qconFactory=(QueueConnectionFactory)ctx.lookup(ConnectionFactoryJNDIName);>
Step 2 -- create a connection)
- Connection:
- Is the communication connection to the JMS Server
- Used to create a session)
- There are two types:
- Queueconnection
- Topicconnection
QueueConnection qcon=qconFactory.createQueueConnection();
Step 3 -- create a session)
- Session:
- Creates a sender, receiver, and empty message.
- Define transactions
- There are two types:
- Queuesession
- Topicsession
Queuesession qsession = qcon. createqueuesesion (false, session. auto_acknowledge); // The session does not use transactions.
Validation Mode
- In a non-transaction session, select one of the following five validation modes for the Application creation session:
- Session. auto_acknowledge
- Session. client_acknowledge
- Session. dups_ OK _acknowledge
- Wlsession. No. Acknowledge
- Wlsession. multicast_no_acknowledge
Next we will discuss these models one by one:
Validation mode (1)
- Session. auto_acknowledge
After the consumer completes message processing, send the confirmation message through the session.
- Session. auto_acknowledge
DGE message confirmation has to be returned from the consumer
- Session. dups_ OK _acknowledge
The session returns the confirmation received by the consumer. if the message is lost, replication is allowed.
Validation mode (2)
- After the wlsession. no_acknowledge message is received, it is immediately deleted from the consumption destination without waiting for confirmation. Therefore, some messages may be lost.
- Wlseesion. multicast_no_acknowledge when broadcasting. The situation is the same as above.
Step 4 -- destination Lookup
- Purpose:
- Is a lightweight object stored in JNDI
- Identify the message target
- There are two types:
Queue queue = (Queue) CTX. Lookup ("queuejndiname"); // The JNDI name is set when Weblogic server is configured in step 3.
Step 5: Send a message
- Message producer:
- Any type of message can be sent to a target.
- Specify distribution options
- There are two types:
- Queuesender
- Topicpublicsher
QueueSender qsender=qsession.createSender(queue);qcon.start();TextMessage msg=qsession.createTextMessage();msg.setText("Hello JMS World");Qsender.send(msg);
JMS message
- A jms message is a class that implements the javax. JMS. Message interface.
- Example:
- Textmessage: Contains strings
- Mapmessage: list containing name/value pairs
- Objectmessage: contains Java objects (must be serializable)
- Streammessage: contains worthy streams.
- Bytemessage: contains a byte array
- You can write your own message types.
Message recipient
- To receive messages from a JMS destination, follow the steps 1-4 described above to find the target.
- Then use the Message Receiver to receive the message:
- Queuereceiver
- Topicsubscriber
QueueReceiver qreceiver=quession.createReceiver(queue);qcon.start();TextMessage msg=(TextMessage)qreceiver.receive();System.out.println("Message is:"+msg.getText());