The scenario is as follows:
The customer will send the original message through the SDK. After receiving the message, the module I am developing will extract and convert the message according to the configuration to generate a new message format , and Passed to downstream modules through mq.
If a pattern is applied, what should it be?
Edited on: June 22, 2017 18:00
Maybe I didn’t describe it clearly, which led to misunderstanding. Please describe the scene in detail:
Receive message
Determine which client the message is sent from, and retrieve the client’s configuration in the background
According to the configuration information, extract and convert messages to generate new format messages
Send new messages to other backend modules for processing
The function you have completed is a converter that limits the format of the required data, such as id, type, and content. You can write an interface with getId, getType, and getContent methods, and require the implementer to provide these values. .
After passing through your converter, you get different objects.
I think it can be achieved like this:
For different messages, there are different message processors (Handler) to complete the corresponding functions, message extraction and new message generation, etc.;
These Handlers implement a common interface, and new Handlers can be added in the future;
All Handlers form a processing chain. Each Handler has a match method to determine whether it should be handled by itself. If it cannot be handled, it will be handed over to the subsequent Handler.
So I think we can consider the responsibility chain model, strategy model, etc.
Such a simple requirement, adapter, just adapt it