I'm using a spring publish subscribe setup whereby events are published to a single channel.

The different events are quite different from each other and deriving the behaviour of the listener from the type would be messy.

I have enough types however that I'm not comfortable with the explosion of a number of different message channels to handle the different types so I'd like to prevent this if possible.

2

There are 2 best solutions below

1
On

take a look at Spring Integration patterns. You can do the pub/sub/channel pattern using just declarative logic.

http://static.springsource.org/spring-integration/reference/html/overview.html

0
On

The requirement is neither for Queue philosophy nor a Topic philosophy...something hybrid in addition with some extra identify receptor logic...I am trying to give a basic idea,

       Message -> this interface will have multiple subclasses for different types of messages
  interface Receptor {
        boolean isMessageDigestable(Message);
        void digestMessage(Message);
        void subscribe(Publisher);
  }

 different receptor will implement Receptor

 class Publisher {

      List<Receptor> receptors;

      void addReceptor(){//your code here};

      void produceMessage() {
          Message m = ....//message production
          for (Receptor r : receptors)
            {
               if (r.isDigestableMessage(m))
                     r.digestMessage(m);
            }
  }