java - About the choice of design patterns
迷茫
迷茫 2017-06-23 09:12:48
0
3
1144

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:

  1. Receive message

  2. Determine which client the message is sent from, and retrieve the client’s configuration in the background

  3. According to the configuration information, extract and convert messages to generate new format messages

  4. Send new messages to other backend modules for processing

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
女神的闺蜜爱上我

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:

  1. For different messages, there are different message processors (Handler) to complete the corresponding functions, message extraction and new message generation, etc.;

  2. These Handlers implement a common interface, and new Handlers can be added in the future;

  3. 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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template