You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by PM <pr...@bigfoot.com> on 2008/02/06 17:34:33 UTC

JMSXGroupID and where to set it

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.
-- 
View this message in context: http://www.nabble.com/JMSXGroupID-and-where-to-set-it-tp15306955s12049p15306955.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: JMSXGroupID and where to set it

Posted by PM <pr...@bigfoot.com>.
Hi,

  Thanks for replying - I am using 3.2.1 at the moment.  The reason I am
using the endpoints I am is because they were the ones that maven put in for
me...  Being new to this I just assumed that it was the right way to go.  Ok
guess not.

  Another reason that I didn't stray too far from the path on this one is
that I had already looked at the new endpoints page, and the only info on
the Provider endpoints is that there is no info ;-(.

  Setting the JMSXGroupID as a simple property in the normalised message,
does indeed work and that is what I did to prove the concept - but in a
service engine elsewhere in the system.  However I felt really that the best
place for it was the marshaler as stuff like this shouldn't be part of a
service engine elsewhere in the process.

  Anyway I shall have a go at stumbling through the new endpoints and
implementing that marshaler.

Thanks & Regards, 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-tp15306955s12049p15333848.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: JMSXGroupID and where to set it

Posted by PM <pr...@bigfoot.com>.
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.


Re: JMSXGroupID and where to set it

Posted by Gert Vanthienen <ge...@skynet.be>.
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.
>>   
>
>


Re: JMSXGroupID and where to set it

Posted by Daryl Richter <ng...@comcast.net>.
Paul-

FWIW, though, the new JMS provider endpoint does not support InOut  
exchanges so you can't use it as-is if you need that functionality.


On Feb 7, 2008, at 7:08 AM, 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.
>>
>

--
Daryl
http://itsallsemantics.com

"We want great men who, when fortune frowns, will not be discouraged."
     -- Colonel Henry Knox, 1776






Re: JMSXGroupID and where to set it

Posted by Gert Vanthienen <ge...@skynet.be>.
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.
>