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.

  • 1
    How long do you expect the recompiling to take? Unless it'll take hours, you probably just want the single program. You should still seperate concerns in the single program and handle send each message type to the proper handler (the same way you would handle HTTP GET , POST, etc). Otherwise you'll likely be overengineering your project and adding in more points of failure. May 26 at 19:08
  • @joshmeranda Good points. Maybe recompiling isn't much of a concern. I was thinking more along the lines of something where I could easily swap out the implementation of handling a single message.
    – Conner
    May 26 at 19:34
  • Thats where separation of concerns comes in! If you write multiple Handler classes to handle each message type (one for GET one for POST, etc) you can easily swap one Handler out for another if you need to change an implementation or for testing. You might also want a getMessage(kind MessageKind) util to isolate where that decision is made May 26 at 19:50
  • @joshmeranda Makes sense! Thanks for the feedback, I had a suspicion I was possibly overengineering it by breaking it out into multiple individual programs.
    – Conner
    May 27 at 13:43
  • Unless you've tested the recompilation and fount it too slow it probably doesn't matter, but you don't necessarily have to recompile the entire program just when you want to change one part. You can compile individual modules of Java code and link them together later.
    – bdsl
    May 28 at 14:05


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.