[英]Message based communication between microservices
I would like to build few number of microservices that send and receive message using a message broker: ActiveMQ . 我想构建一些使用消息代理发送和接收消息的微服务: ActiveMQ 。 Now I am exploring options for message type (ie String
, byte[]
, object type): 现在,我正在探索消息类型(即String
, byte[]
, 对象类型)的选项:
These are the 3 options I have looked at, and I am leaning towards option 1 for below mentioned reasons : 这些是我研究过的3个选项,出于以下原因,我倾向于选择1:
However this raises the issue of parsing and extracting data which is very error prone. 但是,这引起了非常容易出错的解析和提取数据的问题。
I would like to know if anyone else has done a similar design and could share their experience and suggest solutions. 我想知道是否还有其他人做过类似的设计并可以分享他们的经验并提出解决方案。 Also if there is a better way to implement communication between microservices using messaging and queues. 同样,如果有更好的方法可以使用消息传递和队列在微服务之间实现通信。
This is the approach I usually take: for each message type, a class is responsible for both encoding the message (generating JSON/XML/whatnot), validating it and parsing it. 这是我通常采用的方法:对于每种消息类型,一个类负责对消息进行编码(生成JSON / XML / whatnot),对其进行验证并对其进行解析。 Classes go into a library that is then used on both the service which is sending the message and on the service that is receiving it. 类进入一个库,然后该库将在发送消息的服务和接收消息的服务上使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.