Hi All, again

  Ok, I just don't believe that anyone has message groups working !!

  I have tried this every which way that I can think of and still my
consumers receive messages randomly

  I am now using the new provider and consumer endpoints aswell.  Basically
my consumers have a marshaler that simply outputs a correlation id (includes
group name) that i set with the provider marshaler.

  The consumer marshaler looks like:

public class ConsumerGroupMarshaler extends DefaultConsumerMarshaler {
    protected void populateMessage(Message message, NormalizedMessage
normalizedMessage) throws Exception {
                super.populateMessage(message, normalizedMessage);

                System.out.println(message.getJMSCorrelationID());
    }
}

  Now for the provider, I have tried 2 ways the first simply setting the
string property on the TextMessage : 

public class ProviderGroupMarshaler extends DefaultProviderMarshaler {
        private static long messageCount = 0;
        private static boolean groupA = true;

    public Message createMessage(MessageExchange exchange, NormalizedMessage
in, Session session) throws Exception {
                Message toSend = super.createMessage(exchange, in, session);

                appendJMSXGroupID(toSend);

        return toSend;
    }

        private void appendJMSXGroupID(Message message) throws Exception {
                /*
                        figure out what group to send here
                */
                if(++messageCount % 5 == 0) {
                        groupA = !groupA;
                }

                if(groupA) {
                        message.setJMSCorrelationID("GroupA" + messageCount);
                        System.out.println("sending message ID == " +
message.getJMSCorrelationID() + " to group a");
                        message.setStringProperty("JMSXGroupID", "GroupA");
                } else {
                        message.setJMSCorrelationID("GroupB" + messageCount);
                        System.out.println("sending message ID == " +
message.getJMSCorrelationID() + " to group b");
                        message.setStringProperty("JMSXGroupID", "GroupB");
                }
        }
}


  And second, setting the JbiConstant.PROTOCOL_HEADERS : 

public class ProviderGroupMarshaler extends DefaultProviderMarshaler {
        private static long messageCount = 0;
        private static boolean groupA = true;
        private static Map protocolHeaderGroupA;
        private static Map protocolHeaderGroupB;

        static {
                protocolHeaderGroupA = new HashMap();
                protocolHeaderGroupA.put("JMSXGroupID", "GroupA");

                protocolHeaderGroupB = new HashMap();
                protocolHeaderGroupB.put("JMSXGroupID", "GroupB");
        }

    public Message createMessage(MessageExchange exchange, NormalizedMessage
in, Session session) throws Exception {
                appendJMSXGroupID(in);

                Message messageOut = super.createMessage(exchange, in, session);

                messageOut.setJMSCorrelationID((groupA ? "GroupA" : "GroupB") +
messageCount);

        return messageOut
    }

        private void appendJMSXGroupID(NormalizedMessage message) throws 
Exception
{
                /*
                        figure out what group to send here
                */
                if(++messageCount % 5 == 0) {
                        groupA = !groupA;
                }

                if(groupA) {
                                
message.setProperty(JbiConstants.PROTOCOL_HEADERS,
protocolHeaderGroupA);
                } else {
                        message.setProperty(JbiConstants.PROTOCOL_HEADERS, 
protocolHeaderGroupB);
                }
        }
}

  What bothers me most is that either way i try, when i knock out my
consumers, send some messages and look at them in AMQ using JConsole - the
only relevant property that is set is "JMSXGroupFirstForConsumer=true"

  Does anyone have this working?  truly?

Regards, frustratedly & hopefully, Paul.



Gert Vanthienen wrote:
> 
> Paul,
> 
> 
> On second thought, another option might be to use the 
> JbiConstants.PROTOCOL_HEADERS.  If you set this property on a 
> NormalizedMessage to contain a Map, the key-value pairs in that map will 
> be added to JMS Message as properties.  So, if you could add a Map to 
> the NormalizedMessage that contains the JMSXGroupID with the 
> corresponding value (e.g. using a servicemix-bean POJO), that might work 
> just as well.
> 
> 
> Gert
> 
> 
> 
> Gert Vanthienen wrote:
>> Paul,
>>
>>
>> ServiceMix 3.2 comes with a few new JMS endpoints (cfr. 
>> http://servicemix.apache.org/servicemix-jms-new-endpoints.html).  The 
>> consumer and provider endpoints have specific Marshaler interfaces 
>> (JmsConsumerMarshaler and JmsProviderMarshaler) that are a lot easier 
>> to implement.
>> If you're stuck with ServiceMix 3.1 somehow, your options are probably 
>> limited to either implementing the JmsMarshaler interface yourself or 
>> take a look at the source for DefaultJmsMarshaler and make sure that 
>> you override all methods that use the 'endpoint' field.
>>
>>
>> Gert
>>
>>
>>
>>
>> PM wrote:
>>> Hi,
>>>
>>>   I was planning on subclassing the DefaultJmsMarshaler in order to 
>>> set the
>>> JMSXGroupID into my outbound JMS messages.
>>>
>>>   Would this be the right place to do it?  There is nowhere else 
>>> really in
>>> my chain of events that seems sensible to do it.
>>>
>>>   The only problem is that the DefaultJmsMarshaler wants a 
>>> JmsEndpoint in
>>> the constructor.  How would I go about providing that?
>>>
>>> Regards, Paul.
>>>   
>>
>>
> 
> 
> 
> -----
> ---
> Gert Vanthienen
> http://www.anova.be
> 

-- 
View this message in context: 
http://www.nabble.com/JMSXGroupID-and-where-to-set-it-tp15306955s12049p15541631.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Reply via email to