I am working on a program that will listen to a queue of incoming message and will process each message differently depending on the metadata of that message. The messages must be processed in order and if a message fails to be processed, it will block the queue until that individual message is processed. The specific technology I am working with is Azure Service Bus, but it could be any queue implementation. The programs that consume the messages will be written in Java.
Is there a recommended approach or best practice for designing a program for consuming these messages?
My first thought was to create a single monolithic program that listens to the queue and processes each message itself. The reason I don't like this approach is that to change the processing of a single message type would require recompiling the entire project.
The other thought I had was to create an individual program for each message type that listens for its corresponding message type and processes it. The downside to this approach seems to be a lot of duplicated code (each program needs to be configured to read the queue). Plus, given the nature of Java, this would likely consume excessive resources.
GET
,POST
, etc). Otherwise you'll likely be overengineering your project and adding in more points of failure.Handler
classes to handle each message type (one forGET
one forPOST
, etc) you can easily swap oneHandler
out for another if you need to change an implementation or for testing. You might also want agetMessage(kind MessageKind)
util to isolate where that decision is made