Dropwizard:微服务架构

Dropwizard: Microservice Architecture

这类似于How to deserialize from a file to different class。但是,我正在使用 Dropwizard 开发微服务。

我有两个服务,服务 A 和服务 B。我在这两个服务之间设置了一个消息队列 (RabbitMQ)。

我正在尝试将 Class A 类型的对象(在服务 A 中定义)从服务 A 发送到服务 B。我没有在服务 B 中导入 class A。但是在服务中B 我定义了 Class B,它与 Class A 完全相同。

当服务 B 尝试反序列化并将对象类型转换为 Class B 时,我在服务 B 中收到 ClassNotFoundException: Class A。

我希望两个罐子尽可能独立。 有没有办法做到这一点。

您可以使用 Apache Avro 在两个服务之间序列化(预定义的 avro 架构)您的对象,或者如果您想在它们之间使用队列。最重要的是,您将降低所需的网络字节数,因为 apache avro 序列化非常好。

你也可以使用 CatainProto 或 ProtoBuffer,但我喜欢 apache avro 方法。