You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2020/10/06 10:19:25 UTC

[GitHub] [camel] rgannu opened a new pull request #4371: CAMEL-15496: Headers and Properties support

rgannu opened a new pull request #4371:
URL: https://github.com/apache/camel/pull/4371


   The additional headers will be added on top of the existing headers
   from the message.
   
   The properties added are only basic AMQP properties as defined in the
   {@link com.rabbitmq.client.AMQP.BasicProperties.Builder}. When the
   message contains already these properties then will be considered and
   these additional properties will be ignored.
   
   Introduced a SimpleDataHolderBean to hold a hashmap for adding any
   header. As with this fix though we can add any header, only
   static/hard-coded values could be associated.
   
   The rabbitmq AMQP basic properties constant keys should not
   have dot or hyphen in their prefixes. This gives problem in trying to
   retrieve the value due to fix of CAMEL-15394. Changed to underscore.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] davsclaus merged pull request #4371: CAMEL-15496: Headers and Properties support

Posted by GitBox <gi...@apache.org>.
davsclaus merged pull request #4371:
URL: https://github.com/apache/camel/pull/4371


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] oscerd commented on pull request #4371: CAMEL-15496: Headers and Properties support

Posted by GitBox <gi...@apache.org>.
oscerd commented on pull request #4371:
URL: https://github.com/apache/camel/pull/4371#issuecomment-718447104


   I don't know if you repackage the connector or you used the archetype, in your steps it's not reported, and by the way this is not related to camel, but to ckc, so this is not the correct place to discuss.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] oscerd commented on pull request #4371: CAMEL-15496: Headers and Properties support

Posted by GitBox <gi...@apache.org>.
oscerd commented on pull request #4371:
URL: https://github.com/apache/camel/pull/4371#issuecomment-718431009


   What you're trying to do is a bit tricky, btw you can do in the following way: 
   1. Create an archetype starting from the original connector: https://camel.apache.org/camel-kafka-connector/latest/archetypes.html
   2. Add the bean you want, for example the SimpleDataHolderBean in the generated project
   3. Repackage the connector as normal connector and deploy it
   4. Use the bean by referencing the class.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] rgannu commented on pull request #4371: CAMEL-15496: Headers and Properties support

Posted by GitBox <gi...@apache.org>.
rgannu commented on pull request #4371:
URL: https://github.com/apache/camel/pull/4371#issuecomment-718425519


   @oscerd / @davsclaus, Could you please let me know how I can set the HashMap entries via sink connector configuration?
   
   I have tried these
   1. The map is empty.. 
   ```
       "camel.sink.endpoint.additionalHeaders": "#bean:addHeaders",
       "camel.beans.addHeaders": "#class:java.util.HashMap",
       "camel.beans.addHeaders[MSG_TYPE]": "${file:/secrets/amqp.properties:analytics.msg.type}",
       "camel.beans.addHeaders[MSG_ORIGINATOR]": "${file:/secrets/amqp.properties:analytics.msg.originator}",
       "camel.beans.addHeaders[DESTINATION]": "${file:/secrets/amqp.properties:analytics.destination}",
   ```
   
   2. I also tried by having my own class which extends from HashMap. Still only empty map is going in..
   ```
   package aero.unifly.analytics.bean;
   
   public class SimpleDataHolderBean extends java.util.HashMap<String, Object> {
   }
   ```
   ```
       "camel.sink.endpoint.additionalHeaders": "#bean:addHeaders",
       "camel.beans.addHeaders": "#class:aero.unifly.analytics.bean.SimpleDataHolderBean",
       "camel.beans.addHeaders[MSG_TYPE]": "${file:/secrets/amqp.properties:analytics.msg.type}",
       "camel.beans.addHeaders[MSG_ORIGINATOR]": "${file:/secrets/amqp.properties:analytics.msg.originator}",
       "camel.beans.addHeaders[DESTINATION]": "${file:/secrets/amqp.properties:analytics.destination}",
   ```
   
   3. When I do not have the `#class`, I get error `No bean could be found in the registry for: addHeaders of type: java.util.Map`
   ```
       "camel.sink.endpoint.additionalHeaders": "#bean:addHeaders",
       "camel.beans.addHeaders[MSG_TYPE]": "${file:/secrets/amqp.properties:analytics.msg.type}",
       "camel.beans.addHeaders[MSG_ORIGINATOR]": "${file:/secrets/amqp.properties:analytics.msg.originator}",
       "camel.beans.addHeaders[DESTINATION]": "${file:/secrets/amqp.properties:analytics.destination}",
   ```
   
   4.
   Test case I am able to set the map in the camel context and use
   ```
       @Override
       protected CamelContext createCamelContext() throws Exception {
           CamelContext context = super.createCamelContext();
   
           myMap = new HashMap<>();
           myMap.put("k1", "v1");
           myMap.put("k2", 1L);
   
           context.getRegistry().bind("myMap", myMap);
   
           return context;
       }
   
       @Test
       public void testResolveParameter() throws Exception {
           @SuppressWarnings("unchecked")
           Map<String, Object> mapGot = EndpointHelper.resolveParameter(context, "#myMap", Map.class);
           assertSame(myMap, mapGot);
       }
   ```
   
   Please let me know how I need to set the Map via the Connector Configuration.
   
   Thanks and Kind Regards
   Ganesh 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] oscerd commented on pull request #4371: CAMEL-15496: Headers and Properties support

Posted by GitBox <gi...@apache.org>.
oscerd commented on pull request #4371:
URL: https://github.com/apache/camel/pull/4371#issuecomment-718460071


   You can do exactly as in your PR, in the archetype add
   
   ```
   package org.apache.camel.component.rabbitmq;
   
   import java.util.HashMap;
   import java.util.Map;
   
   public class SimpleDataHolderBean {
       private Map<String, Object> mapData;
   
       public SimpleDataHolderBean() {
           this.mapData = new HashMap<>();
       }
   
       public Map<String, Object> getMapData() {
           return mapData;
       }
   
       public void setMapData(Map<String, Object> mapData) {
           this.mapData = mapData;
       }
   
       @Override
       public String toString() {
           return "SimpleDataHolderBean{" +
                  "mapData=" + mapData +
                  '}';
       }
   }
   ```
   
   and use it as class.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] rgannu edited a comment on pull request #4371: CAMEL-15496: Headers and Properties support

Posted by GitBox <gi...@apache.org>.
rgannu edited a comment on pull request #4371:
URL: https://github.com/apache/camel/pull/4371#issuecomment-717934206


   @oscerd/@davsclaus,
    As part of this PR I created a file `components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/SimpleDataHolderBean.java`  and this bean class is missing in the [camel-3.6.0](https://github.com/apache/camel/tree/camel-3.6.0/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq) and in the [master](https://github.com/apache/camel/tree/master/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] rgannu commented on pull request #4371: CAMEL-15496: Headers and Properties support

Posted by GitBox <gi...@apache.org>.
rgannu commented on pull request #4371:
URL: https://github.com/apache/camel/pull/4371#issuecomment-717934206


   @oscerd/@davsclaus,
    As part of this PR I created a file `components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/SimpleDataHolderBean.java`  and this bean class is missing in the `[camel-3.6.0](https://github.com/apache/camel/tree/camel-3.6.0/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq)` and in the `[master](https://github.com/apache/camel/tree/master/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq)`
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] rgannu commented on pull request #4371: CAMEL-15496: Headers and Properties support

Posted by GitBox <gi...@apache.org>.
rgannu commented on pull request #4371:
URL: https://github.com/apache/camel/pull/4371#issuecomment-718553721


   > Or at least this is what you were doing originally.
   
   Thanks a lot. Will try it out as suggested... 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] oscerd commented on pull request #4371: CAMEL-15496: Headers and Properties support

Posted by GitBox <gi...@apache.org>.
oscerd commented on pull request #4371:
URL: https://github.com/apache/camel/pull/4371#issuecomment-718460774


   Or at least this is what you were doing originally.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] rgannu commented on pull request #4371: CAMEL-15496: Headers and Properties support

Posted by GitBox <gi...@apache.org>.
rgannu commented on pull request #4371:
URL: https://github.com/apache/camel/pull/4371#issuecomment-718032898


   > It has been removed [d376711#diff-b2917cb1b72d2ff1600107b5fd43fcd873c1b2dd8bcc7cb165259b3b3782d410](https://github.com/apache/camel/commit/d376711c170500364025064799d8fcf6907c2fde#diff-b2917cb1b72d2ff1600107b5fd43fcd873c1b2dd8bcc7cb165259b3b3782d410)
   
   ok. I wasn't aware of that.. 
   From sink connector json configuration, how do I pass in the map?
   I couldn't do that with the following configuration.. 
   
   ```
       "camel.sink.endpoint.additionalProperties": "#bean:addProperties",
       "camel.beans.addProperties": "#class:java.util.HashMap",
       "camel.beans.addProperties[CamelRabbitmqContentType]": "${file:/secrets/amqp.properties:analytics.content.type}",
       "camel.beans.addProperties[CamelRabbitmqContentEncoding]": "${file:/secrets/amqp.properties:analytics.content.encoding}",
       "camel.beans.addProperties[CamelRabbitmqAppId]": "${file:/secrets/amqp.properties:analytics.app.id}",
   
       "camel.sink.endpoint.additionalHeaders": "#bean:addHeaders",
       "camel.beans.addHeaders": "#class:java.util.HashMap",
       "camel.beans.addHeaders[MSG_TYPE]": "${file:/secrets/amqp.properties:analytics.msg.type}",
       "camel.beans.addHeaders[MSG_ORIGINATOR]": "${file:/secrets/amqp.properties:analytics.msg.originator}",
       "camel.beans.addHeaders[DESTINATION]": "${file:/secrets/amqp.properties:analytics.destination}",
   
   ```
   
   It is not getting set.. Something that I miss ?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] rgannu edited a comment on pull request #4371: CAMEL-15496: Headers and Properties support

Posted by GitBox <gi...@apache.org>.
rgannu edited a comment on pull request #4371:
URL: https://github.com/apache/camel/pull/4371#issuecomment-718425519


   @oscerd / @davsclaus, Could you please let me know how I can set the HashMap entries via sink connector configuration?
   
   I have tried these
   1. The map is empty..
   ```
       "camel.sink.endpoint.additionalHeaders": "#bean:addHeaders",
       "camel.beans.addHeaders": "#class:java.util.HashMap",
       "camel.beans.addHeaders[MSG_TYPE]": "${file:/secrets/amqp.properties:analytics.msg.type}",
       "camel.beans.addHeaders[MSG_ORIGINATOR]": "${file:/secrets/amqp.properties:analytics.msg.originator}",
       "camel.beans.addHeaders[DESTINATION]": "${file:/secrets/amqp.properties:analytics.destination}",
   ```
   ```
   2020-10-29 07:46:05,843 DEBUG  ||  Additional headers: {}   [org.apache.camel.component.rabbitmq.RabbitMQComponent]
   2020-10-29 07:46:05,843 DEBUG  ||  Additional properties: {}   [org.apache.camel.component.rabbitmq.RabbitMQComponent]
    :
    :
   ----------------------
      [org.apache.camel.processor.errorhandler.DefaultErrorHandler]
   java.lang.UnsupportedOperationException
           at java.base/java.util.Collections$UnmodifiableMap.putAll(Collections.java:1463)
           at org.apache.camel.component.rabbitmq.RabbitMQMessageConverter.buildProperties(RabbitMQMessageConverter.java:103)
           at org.apache.camel.component.rabbitmq.RabbitMQMessagePublisher.publish(RabbitMQMessagePublisher.java:96)
           at org.apache.camel.component.rabbitmq.RabbitMQEndpoint.publishExchangeToChannel(RabbitMQEndpoint.java:232)
           at org.apache.camel.component.rabbitmq.RabbitMQProducer$2.doWithChannel(RabbitMQProducer.java:311)
           at org.apache.camel.component.rabbitmq.RabbitMQProducer$2.doWithChannel(RabbitMQProducer.java:308)
           at org.apache.camel.component.rabbitmq.RabbitMQProducer.execute(RabbitMQProducer.java:95)
           at org.apache.camel.component.rabbitmq.RabbitMQProducer.basicPublish(RabbitMQProducer.java:308)
           at org.apache.camel.component.rabbitmq.RabbitMQProducer.processInOnly(RabbitMQProducer.java:294)
           at org.apache.camel.component.rabbitmq.RabbitMQProducer.process(RabbitMQProducer.java:208)        at org.apache.camel.support.LazyStartProducer.process(LazyStartProducer.java:57)
   ```
   As the map is empty I believe the `java.lang.UnsupportedOperationException` exception is coming.
   
   2. I also tried by having my own class which extends from HashMap. Still only empty map is going in..
   ```
   package aero.unifly.analytics.bean;
   
   public class SimpleDataHolderBean extends java.util.HashMap<String, Object> {
   }
   ```
   ```
       "camel.sink.endpoint.additionalHeaders": "#bean:addHeaders",
       "camel.beans.addHeaders": "#class:aero.unifly.analytics.bean.SimpleDataHolderBean",
       "camel.beans.addHeaders[MSG_TYPE]": "${file:/secrets/amqp.properties:analytics.msg.type}",
       "camel.beans.addHeaders[MSG_ORIGINATOR]": "${file:/secrets/amqp.properties:analytics.msg.originator}",
       "camel.beans.addHeaders[DESTINATION]": "${file:/secrets/amqp.properties:analytics.destination}",
   ```
   
   3. When I do not have the `#class`, I get error `No bean could be found in the registry for: addHeaders of type: java.util.Map`
   ```
       "camel.sink.endpoint.additionalHeaders": "#bean:addHeaders",
       "camel.beans.addHeaders[MSG_TYPE]": "${file:/secrets/amqp.properties:analytics.msg.type}",
       "camel.beans.addHeaders[MSG_ORIGINATOR]": "${file:/secrets/amqp.properties:analytics.msg.originator}",
       "camel.beans.addHeaders[DESTINATION]": "${file:/secrets/amqp.properties:analytics.destination}",
   ```
   
   4.
   Test case I am able to set the map in the camel context and use
   ```
       @Override
       protected CamelContext createCamelContext() throws Exception {
           CamelContext context = super.createCamelContext();
   
           myMap = new HashMap<>();
           myMap.put("k1", "v1");
           myMap.put("k2", 1L);
   
           context.getRegistry().bind("myMap", myMap);
   
           return context;
       }
   
       @Test
       public void testResolveParameter() throws Exception {
           @SuppressWarnings("unchecked")
           Map<String, Object> mapGot = EndpointHelper.resolveParameter(context, "#myMap", Map.class);
           assertSame(myMap, mapGot);
       }
   ```
   
   Please let me know how I need to set the Map via the Connector Configuration.
   
   Thanks and Kind Regards
   Ganesh 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] oscerd commented on pull request #4371: CAMEL-15496: Headers and Properties support

Posted by GitBox <gi...@apache.org>.
oscerd commented on pull request #4371:
URL: https://github.com/apache/camel/pull/4371#issuecomment-717937673


   It has been removed https://github.com/apache/camel/commit/d376711c170500364025064799d8fcf6907c2fde#diff-b2917cb1b72d2ff1600107b5fd43fcd873c1b2dd8bcc7cb165259b3b3782d410


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] rgannu commented on pull request #4371: CAMEL-15496: Headers and Properties support

Posted by GitBox <gi...@apache.org>.
rgannu commented on pull request #4371:
URL: https://github.com/apache/camel/pull/4371#issuecomment-718445168


   > What you're trying to do is a bit tricky, btw you can do in the following way:
   > 
   > 1. Create an archetype starting from the original connector: https://camel.apache.org/camel-kafka-connector/latest/archetypes.html
   > 2. Add the bean you want, for example the SimpleDataHolderBean in the generated project
   > 3. Repackage the connector as normal connector and deploy it
   > 4. Use the bean by referencing the class.
   
   Thanks @oscerd .. 
   I thought this is what I tried in step 2 ? Or am i missing something?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org