You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Abhishek Kumar <ma...@gmail.com> on 2018/06/20 13:29:33 UTC

how to set ServiceBus Message properties like MessageID, ContentType, PartitionKey ?

Hi Team,

I am using "qpid-jms-client-0.33.0" and publishing message to ServiceBus.

We have requirement to set service bus Message Properties like MessageID,
ContentType, PartitionKey, CorrelationId, ReplyTo.

I am able to set CorrelationId and ReplyTo but not able to set MessageID,
ContentType and PartitionKey.

Please find below code snippet which i used set properties. Please find
attached screenshot (ServiceBus_Message_Properties.png).

ContentType - I setted "ContentType" but it is coming as custom properties
not as a Message Properties.
PartitionKey - I setted "PartitionKey" but it is coming as custom
properties not as a Message Properties.
MessageID - Not reflected at all. Publishing default messageID.

Am i missing something, please suggest your opinion to achieve above
functionality.

///Code Snippet///

MessageProducer messageProducer = session.createProducer(destination);

TextMessage textMessage = session.createTextMessage("Hello");
textMessage.setJMSMessageID("akdhadsajksd-123-1232131");
textMessage.setObjectProperty("PartitionKey", 333);
textMessage.setJMSType("application/json");
textMessage.setObjectProperty("ContentType", "application/json");

Destination replyTo = session.createQueue("connector-test");
textMessage.setJMSReplyTo(replyTo );

textMessage.setJMSCorrelationID("akdhadsajksd-123-1232131");


Regards,
Abhishek Kumar

Re: how to set ServiceBus Message properties like MessageID, ContentType, PartitionKey ?

Posted by akabhishek1 <ma...@gmail.com>.
Please find attached screenShot.

<http://qpid.2158936.n2.nabble.com/file/t396358/ServiceBus_Message_Properties.png> 



--
Sent from: http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: how to set ServiceBus Message properties like MessageID, ContentType, PartitionKey ?

Posted by akabhishek1 <ma...@gmail.com>.
HI Robbie,

I have two questions. Could you please suggest your opinion on below two
questions. 

1. JMS Type - While sending the message to ServiceBus, we can set JMS type
like "message.setJMSType("Abhishek")" .
              After publishing this message, i can see JMS Type as "Label"
of serviceBus message header.
			  I think vaklue of JMSType should populate as "ContentType". Is it
correct/expected behaviour? Please find attached
screenshot(ServiceBus_Message_Properties_Type.png).
			  Please suggest. 

2. PartitionKey - As this is part of infrastructure header properties. Is
there any way to publish/receive PartitionKey from qpid-jms-client?

Regards,
Abhishek Kumar
ServiceBus_Message_Properties_Type.png
<http://qpid.2158936.n2.nabble.com/file/t396358/ServiceBus_Message_Properties_Type.png>  



--
Sent from: http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: how to set ServiceBus Message properties like MessageID, ContentType, PartitionKey ?

Posted by Robbie Gemmell <ro...@gmail.com>.
The client maps the JMSType header value to the AMQP message
Properties section Subject field, as described by the AMQP JMS Mapping
doc it implements. I assume that SB terms this field as the 'Label'
for the message, and with that being the case then it is expected yes.

As I have mentioned previously in the thread, I think you could use
reflection on the message implementation to achieve what you want for
the PartitionKey 'property', which as noted I expected is actually an
AMQP message-annotation. A quick Google suggests that is the case,
with the annotation key being used likely "x-opt-partition-key". The
internal annotation bits that exist are in the same
AmqpJmsMessageFacade class that I previously noted.

Robbie

On 29 June 2018 at 13:55, akabhishek1 <ma...@gmail.com> wrote:
> Hi Robbie,
>
> Could you please suggest your opinion on below two query.
>
> 1. JMS Type - While sending the message to ServiceBus, we can set JMS type
> like "message.setJMSType("Abhishek")" .
>               After publishing this message, i can see JMS Type as "Label"
> of serviceBus message header.
>                           I think value of JMSType should populate as
> "ContentType". Is it
> correct/expected behaviour? Please find attached
> screenshot(ServiceBus_Message_Properties_Type.png).
>                           Pl ServiceBus_Message_Properties_Type.png
> <http://qpid.2158936.n2.nabble.com/file/t396358/ServiceBus_Message_Properties_Type.png>
> ease suggest.
>
> 2. PartitionKey - As this is part of infrastructure header properties. Is
> there any way to publish/receive PartitionKey from qpid-jms-client?
>
> Regards,
> Abhishek Kumar
>
>
>
> --
> Sent from: http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: how to set ServiceBus Message properties like MessageID, ContentType, PartitionKey ?

Posted by akabhishek1 <ma...@gmail.com>.
Hi Robbie,

Could you please suggest your opinion on below two query. 

1. JMS Type - While sending the message to ServiceBus, we can set JMS type 
like "message.setJMSType("Abhishek")" . 
              After publishing this message, i can see JMS Type as "Label" 
of serviceBus message header. 
                          I think value of JMSType should populate as
"ContentType". Is it 
correct/expected behaviour? Please find attached 
screenshot(ServiceBus_Message_Properties_Type.png). 
                          Pl ServiceBus_Message_Properties_Type.png
<http://qpid.2158936.n2.nabble.com/file/t396358/ServiceBus_Message_Properties_Type.png> 
ease suggest. 

2. PartitionKey - As this is part of infrastructure header properties. Is 
there any way to publish/receive PartitionKey from qpid-jms-client? 

Regards,
Abhishek Kumar



--
Sent from: http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: how to set ServiceBus Message properties like MessageID, ContentType, PartitionKey ?

Posted by akabhishek1 <ma...@gmail.com>.
HI Robbie, 

Thank you so much for your quick reply.Highly appreciated for your help over
weekend. 

It solves my problem. I am able to set contentType with the use of facade
and also able to send property name with dot and hyphen. 

Regards,
Abhishek Kumar



--
Sent from: http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: how to set ServiceBus Message properties like MessageID, ContentType, PartitionKey ?

Posted by Robbie Gemmell <ro...@gmail.com>.
As the documentation mentions, you can disable the property name
restrictions if you desire, using the "jms.validatePropertyNames" URI
option, http://qpid.apache.org/releases/qpid-jms-0.33.0/docs/index.html#jms-configuration-options.
Be aware that using any such non-JMS identifiers means your code may
not be portable to other JMS implementations in future.

As I noted before, you may also be able to reach into the newer JMS
clients message implementation to set the content type using
reflection if you really want. Its not quite as simple as with the
older prototype client you reference below, and there is no plan to
expose it in a similar way. The bit of interest would be in the
JmsMessage objects 'facade' field, where the implementation class,
AmqpJmsMessageFacade, currently has a setContentType method for
internal usage.

Robbie

On 22 June 2018 at 15:33, akabhishek1 <ma...@gmail.com> wrote:
> Hi Robbie,
>
> Thanks a lot for reply and detail explanation.
>
> I went through
> "http://docs.oasis-open.org/amqp/core/v1.0/amqp-core-messaging-v1.0.html#section-message-format"
> and
> understood that there could be the infrastructure property as well.
>
> Some Difference between AMQP and JMS standard
> 1. AMQP  support property name as String but JMS supports only letter,
> digit, symbol, punctuation character etc which allows "java.lang.Character
> -> isJavaIdentifierPart"
>    SO JMS can not allow property name with dot, hyphen.
> 2. AMQP supports infrastructure property as part of header property.
> Qpid-Client-JMS does not provide facility to insert infrastructure property.
>    We can not change ContentType as well(part of header property).
>
>
> My understanding is that Service Bus is probably using AMQP compatible
> messages, but we are using the "qpid-jms-client" library to handle these
> messages.
> This seems to cause a mismatch between what AMQP / Service Bus is sending in
> messages and what the JMS client can manage.
> Is using the JMS client the bst approach?  Are there other options?
>
> I also did some research based on "qpid-amqp-1-0-client-jms-0.32". With the
> use of this, i can get hold on
> "org.apache.qpid.amqp_1_0.jms.impl.MessageImpl".
> I am able to set "ContentType". Please find attached example. The main
> problem - "qpid-amqp-1-0-client-jms-0.32" is a old library and no release
> after "Mar, 2015".
>
> Is that possible for you to provide same functionality in "qpid-jms-client"
> ? Please suggest.
>
> We are worried about "ContentType" only. We can use ASIS message id and
> default partition key.
>
> Please suggest your opinion depends on your input we will proceed further.
>
> Regards,
> Abhishek Kumar
>
> TestQpid_1_0_JMS_TemplateSend.java
> <http://qpid.2158936.n2.nabble.com/file/t396358/TestQpid_1_0_JMS_TemplateSend.java>
>
>
>
> --
> Sent from: http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: how to set ServiceBus Message properties like MessageID, ContentType, PartitionKey ?

Posted by akabhishek1 <ma...@gmail.com>.
Hi Robbie, 

Thanks a lot for reply and detail explanation. 

I went through
"http://docs.oasis-open.org/amqp/core/v1.0/amqp-core-messaging-v1.0.html#section-message-format"
and 
understood that there could be the infrastructure property as well.

Some Difference between AMQP and JMS standard
1. AMQP  support property name as String but JMS supports only letter,
digit, symbol, punctuation character etc which allows "java.lang.Character
-> isJavaIdentifierPart"
   SO JMS can not allow property name with dot, hyphen.
2. AMQP supports infrastructure property as part of header property.
Qpid-Client-JMS does not provide facility to insert infrastructure property.
   We can not change ContentType as well(part of header property). 


My understanding is that Service Bus is probably using AMQP compatible
messages, but we are using the "qpid-jms-client" library to handle these
messages.  
This seems to cause a mismatch between what AMQP / Service Bus is sending in
messages and what the JMS client can manage.  
Is using the JMS client the bst approach?  Are there other options?

I also did some research based on "qpid-amqp-1-0-client-jms-0.32". With the
use of this, i can get hold on
"org.apache.qpid.amqp_1_0.jms.impl.MessageImpl". 
I am able to set "ContentType". Please find attached example. The main
problem - "qpid-amqp-1-0-client-jms-0.32" is a old library and no release
after "Mar, 2015".

Is that possible for you to provide same functionality in "qpid-jms-client"
? Please suggest. 

We are worried about "ContentType" only. We can use ASIS message id and
default partition key. 

Please suggest your opinion depends on your input we will proceed further. 

Regards,
Abhishek Kumar

TestQpid_1_0_JMS_TemplateSend.java
<http://qpid.2158936.n2.nabble.com/file/t396358/TestQpid_1_0_JMS_TemplateSend.java>  



--
Sent from: http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: how to set ServiceBus Message properties like MessageID, ContentType, PartitionKey ?

Posted by Robbie Gemmell <ro...@gmail.com>.
The message ID is set by the JMS client during the send() call per the
JMS spec, it isn't possible for you to set it. As covered in its
documentation, the message.setJMSMessageID() is not for use by
applications, but by JMS implementations (to use when another
implementations message objects are sent).

The PartitionKey 'property' being referred to is I expect a custom
AMQP message-annotation (one I'd guess is not actually named
'PartitionKey'), the JMS client does not surface a way to access
these. The ContentType property is presumably the content-type field
of the AMQP Properties section, the JMS client again does not surface
a way to use this. In these latter two cases, it may be possible to
reach deep into the innards of the Message implementations using
reflection and manipulate it to achieve what you want, but if it is
possible it will be convoluted and brittle.

Robbie

On 20 June 2018 at 14:29, Abhishek Kumar
<ma...@gmail.com> wrote:
> Hi Team,
>
> I am using "qpid-jms-client-0.33.0" and publishing message to ServiceBus.
>
> We have requirement to set service bus Message Properties like MessageID,
> ContentType, PartitionKey, CorrelationId, ReplyTo.
>
> I am able to set CorrelationId and ReplyTo but not able to set MessageID,
> ContentType and PartitionKey.
>
> Please find below code snippet which i used set properties. Please find
> attached screenshot (ServiceBus_Message_Properties.png).
>
> ContentType - I setted "ContentType" but it is coming as custom properties
> not as a Message Properties.
> PartitionKey - I setted "PartitionKey" but it is coming as custom properties
> not as a Message Properties.
> MessageID - Not reflected at all. Publishing default messageID.
>
> Am i missing something, please suggest your opinion to achieve above
> functionality.
>
> ///Code Snippet///
>
> MessageProducer messageProducer = session.createProducer(destination);
>
> TextMessage textMessage = session.createTextMessage("Hello");
> textMessage.setJMSMessageID("akdhadsajksd-123-1232131");
> textMessage.setObjectProperty("PartitionKey", 333);
> textMessage.setJMSType("application/json");
> textMessage.setObjectProperty("ContentType", "application/json");
>
> Destination replyTo = session.createQueue("connector-test");
> textMessage.setJMSReplyTo(replyTo );
>
> textMessage.setJMSCorrelationID("akdhadsajksd-123-1232131");
>
>
> Regards,
> Abhishek Kumar
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org