Announcement Announcement Module
Collapse
No announcement yet.
How to use MessageTemplate with subtopics? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use MessageTemplate with subtopics?

    Hi,

    I'd like to know how can I use MessageTemplate to create and send a message to a given subtopic.

    I'm meaning something like:

    template.send( "messageChannel", whatever_i_want_to_send, subtopic );

    Cause, in the MessageTemplate reference, I can't see any method or overloaded method to do that.

    I can use template.send to send anything directly without using subtopics, this automatically creates an AsyncMessage and sends it using the given destination, but I can't seen how I can tell the "send" method to create that AsyncMessage with a subtopic header.

    I could do :

    AsyncMessage msg = template.createMessageForDestination("messageChann el");
    msg.setHeader("DSSubtopic", subTopic);

    and then use:

    template.getMessageBroker().routeMessageToService( msg, null );

    That will work but maybe it could be useful to have an overloaded send method to do that?

    Thanks.
    Last edited by aalbericio; Jul 27th, 2009, 02:12 PM.

  • #2
    Hi Alberto,
    I'm not sure if you solved it or not. You can overload your own messaging methods to set the header.
    I do this, it works:

    template = new MessageTemplate();
    MessageBroker mb = MessageBroker.getMessageBroker("_messageBroker");
    template.setMessageBroker( mb );
    template.send(new AsyncMessageCreator() {
    public AsyncMessage createMessage() {
    AsyncMessage msg = template.createMessageForDestination("your_dest");
    msg.setHeader( "DSSubtopic", "your_subtopic");
    msg.setBody(mesaj);
    return msg;
    }
    });

    Just an observation: I noticed you create your message for a "messageChannel"? It should be destination.

    Regards,
    Radu

    Comment


    • #3
      Hi Raduf,

      I used the code from my first post. I just wanted to ask there was any other ( more high level ) way to send a message to a subtopic.

      "messageChannel" was the message destination in my project so everything worked fine.

      Thanks for your reply.

      A.

      Comment


      • #4
        Originally posted by raduf View Post
        Hi Alberto,
        I'm not sure if you solved it or not. You can overload your own messaging methods to set the header.
        I do this, it works:

        template = new MessageTemplate();
        MessageBroker mb = MessageBroker.getMessageBroker("_messageBroker");
        template.setMessageBroker( mb );
        template.send(new AsyncMessageCreator() {
        public AsyncMessage createMessage() {
        AsyncMessage msg = template.createMessageForDestination("your_dest");
        msg.setHeader( AsyncMessage.SUBTOPIC_HEADER_NAME, "your_subtopic");
        msg.setBody(mesaj);
        return msg;
        }
        });

        Just an observation: I noticed you create your message for a "messageChannel"? It should be destination.

        Regards,
        Radu
        This solution works. I would use the subtopic header name constant in the AsyncMessage class.

        Comment

        Working...
        X