7 Replies Latest reply on Feb 2, 2016 5:16 AM by Tomohisa igarashi

    JMS message selector

    Max Ozkin Apprentice

      Any examples and/or advices how to use message selectors with either JMS or JCA (with JMS) binding and reference?

      I could not find any examples. The idea is simple: one component sending messages with certain property (header) to a topic, and another component consuming from the topic only those messages which contain that property (using selector).

        • 1. Re: JMS message selector
          Tomohisa igarashi Master

          There's a "selector" field if you open SwitchYard camel-jms binding properties tab in the SwitchYard editor. And "messageSelector" can be specified as a ActivationSpec property on JCA service binding as per JCA spec.

          • 2. Re: JMS message selector
            Max Ozkin Apprentice

            Handling of inbound jms messages is more or less clear, just as you said, using "selector" or "messageSelector" fields. If I understood right the selector can contain expressions with message header or message property values.

            But what would be the right way to set those values when sending jms messages using either jca-jms or camel-jms reference bindings?

            I guess when one needs to set a message header or message property he cannot use the reference defined with @Inject @Reference MyService but rather should use ReferenceInvoker because otherwise there is no access to those fields. Is that correct?

            Or should one use the custom MessageComposer instead for setting those values for outgoing jms messages?


            Btw, what is the meaning of "Selector" field in JMS reference binding in SY editor?

            • 3. Re: JMS message selector
              Tomohisa igarashi Master

              There's no way to specify selector on producer, it's only available for consumer. See JMS spec. The selector field will be ignored for JMS reference binding.

              • 4. Re: JMS message selector
                Max Ozkin Apprentice

                Yes, that's what I thought as well... but for me more important is other questions about how to specify values on outbound messages in SY, which are later used in selectors. Any hints?

                • 5. Re: JMS message selector
                  Tomohisa igarashi Master

                  Ah OK so you're looking for a way to set a JMS property when sending via reference binding? Basically the SwitchYard context properties will be mapped into JMS properties, and it requires ReferenceInvoker to do it from bean service. Not sure exactly for now though, I think you can use setHeader from camel route service to do the same.

                  Message Composition - SwitchYard - Project Documentation Editor

                  • 6. Re: JMS message selector
                    Max Ozkin Apprentice

                    Yes. So, two approaches worked for me (when doing this from a Bean).


                    1) using ReferenceInvoker:




                      private ReferenceInvoker myService;


                      public void foo() throws Exception {

                        ReferenceInvocation ri = myService.newInvocation();

                        ri.setProperty("customHeaderName", "customHeaderValue");




                    2) using custom JMSMessageComposer:


                      public class MyCustomComposer extends JMSMessageComposer {


                        public JMSBindingData decompose(Exchange exchange, JMSBindingData target) throws Exception {

                          exchange.getContext().setProperty("customHeaderName", "customHeaderValue", Scope.MESSAGE);

                          target = super.decompose(exchange, target);

                          return target;




                    Any hints which one would be more preferable or is it a matter of personal taste? or what other alternatives exist?

                    • 7. Re: JMS message selector
                      Tomohisa igarashi Master

                      That depends - for example if that property is calculated from business logic then that definitely should be done by service implementation. If that property is a common one which is always included in incoming message, then I would choose ContextMapper. I would think the ContextMapper is a tool to get rid of common property processing from business logic.