What is an asynchronous communication process with loosely coupled messages?
What is a message
Loosely coupled asynchronous communication process
1. Message-oriented middleware (MOM): message sender is called the producer; the location where the message is stored is called the destination; the component that receives the message is called the consumer
2. Message model:
a. Point-to-point: The destination becomes a queue, and the message can only be consumed once
b. Publish-subscribe: The destination becomes the subject, the consumer is called a subscriber, and the message can be consumed by any number
Java Message Service
1. JMS API: Provides a unified and standard way to access MOM (message middleware) using Java
2. Develop message producer process:
a. Use dependency injection to obtain the connection factory ConnectionFactory and destination Destination objects
b. Use createConnection of the connection factory to open the connection Connection
c. Use createSession of Connection to create a session and specify transaction parameters
d. Use the createProducer of the session to create the freight queue Producer
e. Use createMessage of Session to create message Message and set
f. Use send of freight queue Producer to send message
g. Release resources
Note: The above process is based on JavaEE 6. JavaEE 7 provides a simpler A development process
3. Message interface: message header, message attributes, message body; implementation class: ObjectMessage transfers objects, ByteMessage transfers bytes, MapMessage transfers Map, StreamMessage transfers stream data, and TextMessage transfers text
Message-driven bean (MDB)
1. Advantages: multi-threading, simplified message code
2. Design principles:
a. The MDB class must directly or indirectly implement the message listener interface
b. It must be concrete and public, it cannot be final or abstract class
c. It must be a POJO and cannot be a subclass of another MDB
d. There must be a constructor without parameters
e. There cannot be a final method
f. No runtime exception can be thrown, because the MDB instance will be terminated when it is thrown
3. Use MDB to develop consumer processes
a. Use the annotation @MessageDriven to mark the class as MDB and specify the MDB configuration
b. Implement the MessageListener interface and implement the onMessage method
c. Implement logic in onMessage
4. @MessageDriven: The annotated class is MDB. This annotation has three parameters. name specifies the name of the MDB. messageListenerInterface specifies the message interface implemented by the MDB (the interface can be implemented directly on the class). activationConfig is used to specify the proprietary Configuration properties
5. MessageLisener: Register MDB as a message consumer and implement different listener interfaces according to different scenarios
6. ActivationConfigProperty: Configure the configuration information of the message system
a. destinationType: informs the container whether the MDB is listening to a queue or a topic
b. connectionFactoryJndiName: Specifies the connection factory JDNI
used to create a JMS connection to the MDB
c. destianName: Specifies the listening destination
d. acknowledgeMode: Specify JMS session confirmation mode
e. subscriptionDurability: used to set as a durable subscriber
f. messageSelector: filter messages
7. MDB life cycle:
a. Create MDB instances and set them up
b. Inject resources
c. Store in a managed pool
d. When detecting the destination where the message arrives, take out the idle bean
from the pool.
e. Execute the message listener method, that is, onMessage method
f. When the onMessage method is executed, save the idle bean back to the pool
g. Revoke/destroy beans from the pool as needed
8. Send messages from MDB: Inject into the queue from JNDI, connect to the factory object, and then perform the same operation as Java messages
9. Manage transactions: Under normal circumstances, the transaction is started before the onMessage method and the transaction is submitted at the end of the method. The transaction can be rolled back through the message context object
MDB best practices
1. Choose whether to use MDB according to usage
2. Choose the message model: PTP or publish-subscribe should be decided during program design, but fortunately, switching between the two only requires modifying the configuration
3. Maintain modularity: MDB’s onMessage method should not handle business logic. Business logic should be placed in the corresponding session bean and injected into MDB. MDB is responsible for calling the corresponding session bean
4. Make full use of filters or divide destinations according to the scenario
5. Select the message type: Select the message type used for transmission according to the usage scenario
6. Be wary of toxic messages: Messages that cannot be consumed but are rolled back will fall into an infinite loop of receiving/rolling back. Although individual manufacturers have their own implementations of processing dead messages, you should pay attention when programming
7. Configure the MDB pool size: Configure according to the scenario and requirements
Reference
EJB 3 in Action, Second Edition
The above is the detailed content of What is an asynchronous communication process with loosely coupled messages?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The message has been sent but rejected by the other party. This means that the sent information has been successfully sent from the device, but for some reason, the other party did not receive the message. More specifically, this is usually because the other party has set certain permissions or taken certain actions, which prevents your information from being received normally.

How to Use Swipe to Reply in iMessages on iPhone Note: The Swipe to Reply feature only works with iMessage conversations in iOS 17, not regular SMS conversations in the Messages app. Open the Messages app on your iPhone. Then, head to the iMessage conversation and simply swipe right on the iMessage you want to reply to. Once this is done, the selected iMessage will be in focus while all other messages will be blurred in the background. You'll see a text box for typing a reply and a "+" icon for accessing iMessage apps like Check-ins, Places, Stickers, Photos, and more. Just enter your message,

In iOS17, Apple has added several new features to its Messages app to make communicating with other Apple users more creative and fun. One of the features is the ability to use emojis as stickers. Stickers have been around in the Messages app for years, but so far, they haven't changed much. This is because in iOS17, Apple treats all standard emojis as stickers, allowing them to be used in the same way as actual stickers. This essentially means you're no longer limited to inserting them into conversations. Now you can also drag them anywhere on the message bubble. You can even stack them on top of each other to create little emoji scenes. The following steps show you how it works in iOS17

The Xiaomi Mi 15 series is expected to be officially released in October, and its full series codenames have been exposed in the foreign media MiCode code base. Among them, the flagship Xiaomi Mi 15 Ultra is codenamed "Xuanyuan" (meaning "Xuanyuan"). This name comes from the Yellow Emperor in Chinese mythology, which symbolizes nobility. Xiaomi 15 is codenamed "Dada", while Xiaomi 15Pro is named "Haotian" (meaning "Haotian"). The internal code name of Xiaomi Mi 15S Pro is "dijun", which alludes to Emperor Jun, the creator god of "The Classic of Mountains and Seas". Xiaomi 15Ultra series covers

Since the Huawei Mate60 series went on sale last year, I personally have been using the Mate60Pro as my main phone. In nearly a year, Huawei Mate60Pro has undergone multiple OTA upgrades, and the overall experience has been significantly improved, giving people a feeling of being constantly new. For example, recently, the Huawei Mate60 series has once again received a major upgrade in imaging capabilities. The first is the new AI elimination function, which can intelligently eliminate passers-by and debris and automatically fill in the blank areas; secondly, the color accuracy and telephoto clarity of the main camera have been significantly upgraded. Considering that it is the back-to-school season, Huawei Mate60 series has also launched an autumn promotion: you can enjoy a discount of up to 800 yuan when purchasing the phone, and the starting price is as low as 4,999 yuan. Commonly used and often new products with great value

1. Being added to the blacklist: The message has been sent but rejected by the other party. Generally, you have been blacklisted. At this time, you will not be able to send messages to the other party, and the other party will not be able to receive your messages. 2. Network problems: If the recipient's network condition is poor or there is a network failure, the message may not be successfully received. At this point, you can try to wait for the network to return to normal before sending the message again. 3. The other party has set up Do Not Disturb: If the recipient has set up Do Not Disturb in WeChat, the sender’s messages will not be reminded or displayed within a certain period of time.

Xiaomi 14Pro is a flagship model with excellent performance and configuration. It has achieved high sales since its official release. Many small functions of Xiaomi 14Pro will be ignored by everyone. For example, it can be set to light up the screen for messages. Although the function is small, , but it is very practical. Everyone will encounter various problems when using the mobile phone. So how to set up the Xiaomi 14Pro to light up the screen for messages? How to set up Xiaomi Mi 14 Pro to light up the screen for messages? Step 1: Open your phone’s Settings app. Step 2: Swipe down until you find the "Lock screen and password" option and click to enter. Step 3: In the "Lock screen & passcode" menu, find and click the "Turn on screen for notifications" option. Step 4: On the "Turn on screen when receiving notifications" page, turn on the switch to enable

The native Messages app on iPhone lets you easily edit sent texts. This way, you can correct your mistakes, punctuation, and even autocorrect wrong phrases/words that may have been applied to your text. In this article, we will learn how to edit messages on iPhone. How to Edit Messages on iPhone Required: iPhone running iOS16 or later. You can only edit iMessage text on the Messages app, and then only within 15 minutes of sending the original text. Non-iMessage text is not supported, so they cannot be retrieved or edited. Launch the Messages app on your iPhone. In Messages, select the conversation from which you want to edit the message
