Search code examples
javajakarta-eejaxbjmsmessaging

How to avoid code duplication for JMS Messages classes?


I'm new to JMS and JavaEE and I'm supposed to implement an enterprise application where communication between modules happens via JMS using a (non-trivial) common data model.

I've been reading a book and documentation but I don't understand how I'm supposed to share the message interface (or schema) between different modules.

Let's say I have an AppCommonDataModelDocument object that I serialize to XML with JAXB and send as a message on a JMS queue, how can the receiver deserialize it? I guess it has to have the same class(es) in its classpath.

So am I supposed to copy the AppCommonDataModelDocument to each module? How do I manage changes to it? With WebService we have WSDL that define the message format, is there something like that for Messaging?


Solution

  • Create a separate module containing the shared message classes, and add a dependency on that shared module in all the modules that need to serialize/deserialize instances of those classes.