J2EE technical specifications (9) -- JMS (JMS client)

Source: Internet
Author: User
Tags qcon

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
  1. Weblogic server implements the JMS service provider (Service Provider) in accordance with the JMS 1.0.2 specification)
  2. 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
  1. In WebLogic Server, message service is implemented through the JMS server.
  2. The JMS server is responsible for interpreting and distributing messages.

Configure WebLogic Server JMS
  1. The process of configuring WebLogic JMS consists of three steps:

    • JMS Server
    • Queue and/or topic
    • Connection Factory (optional)
Write a simple JMS Client
  1. Configure JMS in WebLogic Server
  2. Write a simple JMS Client

    • Compile a simple JMS producer
    • Write a simple JMS consumer
  1. Send message
  2. Receive messages
  3. 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)
  1. 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)
  1. 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)
  1. 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
  1. 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)

  1. Session. auto_acknowledge
    After the consumer completes message processing, send the confirmation message through the session.
  2. Session. auto_acknowledge
    DGE message confirmation has to be returned from the consumer
  3. Session. dups_ OK _acknowledge
    The session returns the confirmation received by the consumer. if the message is lost, replication is allowed.

Validation mode (2)

  1. 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.
  2. Wlseesion. multicast_no_acknowledge when broadcasting. The situation is the same as above.
Step 4 -- destination Lookup
  1. Purpose:

    • Is a lightweight object stored in JNDI
    • Identify the message target
    • There are two types:
      • Queue
      • Topic

Queue queue = (Queue) CTX. Lookup ("queuejndiname"); // The JNDI name is set when Weblogic server is configured in step 3.

Step 5: Send a message
  1. 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
  1. A jms message is a class that implements the javax. JMS. Message interface.
  2. 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
  3. You can write your own message types.

Message recipient

  1. To receive messages from a JMS destination, follow the steps 1-4 described above to find the target.
  2. 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());

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.