Thank you so much Chris!

To sum up what changes I had to do to my code:

 * Supply routing key (using the trick with typecast to
   AmqpJmsMessageFacade). I was in fact specifically grepping the
   jms-client sources to find how it handles "subject", but I missed
   the fact that there is the qpid proton library for Java
 * for some strange reason remove request.setJMSType("amqp/map");
 * Change the response handling as QMF now responds with
   JmsObjectMessage instead of MapMessage and it also uses
   org.apache.qpid.proton.amqp.Binary in the inner parts of the message
 * request.setValidatePropertyNames(false); - this one was also quite
   tricky, thanks

I hope that migrating other parts of the code won't be as tricky as this :-)

On 12/19/2016 05:40 PM, Chris Richardson wrote:
Hi Filip,

I think I might have had the same problem as you in the past because the methods (I think) are required are not available on the JMS interface. My solution was a rather hacky approach of casting the JMS instance to the actual Qpid type, as in the following examples:

   private  void  method(String  method,  Map  arguments,  String  address)  
throws  JMSException  {
         Destination  reply_to  =  session.createTemporaryQueue();
         MessageConsumer  receiver  =  session.createConsumer(reply_to);

         JmsMapMessage  request  =  (JmsMapMessage)  session.createMapMessage();
         request.setValidatePropertyNames(false);
         request.setStringProperty("x-amqp-0-10.app-id",  "qmf2");
         request.setStringProperty("qmf.opcode",  "_method_request");
         request.setStringProperty("method",  "request");

         Map  object_id_map  =  new  HashMap();
         object_id_map.put("_object_name",  address);

         request.setString("_method_name",  method);

         // Can't set map directly on object, so we'll hack it here
         JmsMapMessageFacade  facade  =  
(JmsMapMessageFacade)request.getFacade();
         facade.put("_object_id",  object_id_map);
         facade.put("_arguments",  arguments);

         int  correlation_id  =  sendMessage(request,  reply_to);

         List<Message>  response  =  awaitResponse(receiver,  correlation_id,  
10  *  1000);
         if  (response  !=  null  &&  response.size()  >  0)  {
             new  ResponseDecoder().decodeResponse(response);
         }  else  {
             throw  new  JMSException("No response received");
         }
     }

     private  int  sendRequest(String  opcode,  Map<String,  ?>  query,  
Destination  replyAddress)  throws  JMSException  {
         JmsMapMessage  request  =  (JmsMapMessage)  session.createMapMessage();
         request.setValidatePropertyNames(false);
         request.setStringProperty("x-amqp-0-10.app-id",  "qmf2");
         request.setStringProperty("qmf.opcode",  opcode);

         // Can't set map directly on object, so we'll hack it here
         JmsMapMessageFacade  facade  =  
(JmsMapMessageFacade)request.getFacade();
         for  (Map.Entry<String,  ?>  entry  :  query.entrySet())  {
             facade.put(entry.getKey(),  entry.getValue());
         }

         return  sendMessage(request,  replyAddress);
     }

Unfortunately I haven't structured our Java implementation of the QMF2 interface as well as I could have done and it's rather entrenched in another of our libraries but I'm sure no one will mind if I share the attached implementation (based on the Qpid Python implementation) for reference.

/Chris


On 19 December 2016 at 14:14, Filip Nguyen <[email protected] <mailto:[email protected]>> wrote:

    We currently use Java JMS qpid-client 0.32. It is quite easy to
    use QMF [1] just by using MapMessage etc.

    With new Java Qpid JMS client
    org.apache.qpid:qpid-jms-client:jar:0.10.0 I couldn't find a way
    how to use Qpid QMF. Is there any existing usage or example how to
    do that?

    [1]

                MapMessage request = session.createMapMessage();
                request.setJMSReplyTo(responseQueue);
                request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
                request.setStringProperty("qmf.opcode", "_query_request");




    ---------------------------------------------------------------------
    To unsubscribe, e-mail: [email protected]
    <mailto:[email protected]>
    For additional commands, e-mail: [email protected]
    <mailto:[email protected]>




--

*Chris Richardson*, System Architect
[email protected] <mailto:[email protected]>

/FourC AS, Vestre Rosten 81, Trekanten, NO-7075 Tiller, Norway
www.fourc.eu <http://www.fourc.eu/>/

*Follow us on LinkedIn <http://bit.ly/fourcli>, Facebook <http://bit.ly/fourcfb>, Google+ <http://bit.ly/fourcgp> and Twitter <http://bit.ly/fourctw>!*



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to