Message sending and receiving program based on WebSphere MQ

Source: Internet
Author: User

Abstract: This article briefly introduces IBM's commercial communication middleware WebSphere MQ from the following aspects. It first explains the significance of message, queue, and queue manager, on this basis, the illustration illustrates the communication mechanism adopted by WebSphere MQ during communication, as well as the relationship between this communication mechanism and various applications for communication. Next, we will use an example to illustrate how to write messages to the queue when writing programs in Java. At last, I briefly introduced the advantages and Development Prospects of MQ.

Keywords: Communication middleware, queue, queue manager, MQ

WebSphere MQ (hereinafter referred to as MQ) is a well-known commercial communication middleware of IBM. It is widely used by many large enterprises around the world. It provides a secure and reliable message transmission system with industrial standards. MQ is basically composed of a message transmission system and an application interface. The application uses the mq api (Message Queue interface MQI) function to communicate with the queue manager (the program at the MQ runtime. When the queue manager is working, it needs to use objects such as queues and channels. The queue manager is also an object. Figure 1 shows the running time of the MQ application.

Figure 1 MQ1 at runtime

A message is an information unit. It consists of two parts: application data sent from one program to another, as well as message descriptors or message headers.

The message descriptor is used to identify a message. It also includes some control information, such as the message type, message expiration time, and message priority.

The maximum length of a message is 100 MB, and the default maximum message length is 4 MB. The maximum message length depends on the MQ version. MQ Fifth Edition supports a maximum message length of 100 MB.

A queue is a safe place to store messages. messages are stored in order. Because messages are stored in queues, applications can run independently at different speeds, at different times, and at different locations.

Message Queue communication is a method of communication between applications. Applications can communicate with each other by writing or reading messages to the queue without a private or physical connection, instead, it sends data to the queue for communication. In this mode of communication, applications do not need to have concurrency. For Asynchronous Message Communication, the sender of the program can process the next event instead of waiting for a reply from the sent message. In contrast, synchronous Message Communication must wait for a reply to the sent message before processing the next event. For users, the underlying protocol is transparent. You only need to consider the program or data entry of the session.

MQ is used in the Client/Server mode or distributed system. Applications can work on one workstation or on different machines on different platforms. Applications are highly portable and can be easily transferred from one system or platform to another. Programming supports multiple languages, including Java. Similarly, queues are suitable for many different platforms.

Because MQ communicates through queues, it can be considered to communicate through indirect programs-programs. The programmer can specify the name of the target program for receiving messages, but the name of the queue for receiving messages. Each queue is associated with a program, A program can have one or more receiving queues and multiple output queues. The output queue contains a lot of information, which can be used by the server or returned to the reply information of the client sending the message.

When using MQ for communication, programmers do not have to worry about whether the target program is available or busy, or even whether the target machine is running normally or connected. The programmer sends a message to the target queue, which is associated with the target program. The target program may be unavailable currently. Don't worry. MQ can solve this problem. If necessary, it can even start the target program.

If the target program is unavailable, the message will stay in the queue and be processed later. The queue can be either in the machine where the message is sent or in the machine where the message is received, depending on whether the two systems of the two machines can establish a connection. An application can run all day, or use the excitation mechanism. The so-called excitation means that a program is automatically started when one or more messages arrive in the queue.

Figure 2 message and queue 1

Figure 2 illustrates how two applications A and B communicate. There are two queues in which messages to be received or sent are stored.

The square diagram between the program and the queue indicates MQI (Message Queue interface API ). The program uses MQI to communicate with the MQ real-time program queue manager.

Simply put, the core part of MQ is a server that can store messages and a group of processes that can forward messages, distributed in multiple systems (remote and heterogeneous platforms) applications rely on this mechanism to exchange the data to be processed 2. As a server, the queue manager stores messages reliably. Even if the server is restarted after a fault occurs, the messages are not lost. The reliability level is equal to that of the database server. The queue manager uses a special exchange mechanism to ensure that data is not lost due to underlying network faults and can be transmitted over multiple points.

JMS is an interface standard in J2EE. It defines a standard programming method for JAVA programs to use message exchange data. However, JMS itself cannot implement message transmission, after a JMS application sends a message call, the underlying message middleware is required for message transmission. The role of JMS is that application developers do not need to care about the types of underlying transmission software. The same program can be transmitted either through MQ or other message middleware, for example, WEBLOGIC contains components with message-oriented middleware features.

Related Article

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.