This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4b10a498ac75b0175e892e4c063d34b1c660a844 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Jan 12 16:21:20 2021 +0100 CAMEL-16003: camel-spring-rabbitmq - New component using spring client --- .../catalog/docs/spring-rabbitmq-component.adoc | 44 +++++++++++++-- .../springrabbit/RabbitMQComponentConfigurer.java | 6 ++ .../component/springrabbit/spring-rabbitmq.json | 1 + .../src/main/docs/spring-rabbitmq-component.adoc | 44 +++++++++++++-- .../DefaultListenerContainerFactory.java | 5 +- .../component/springrabbit/RabbitMQComponent.java | 10 ++++ .../component/springrabbit/RabbitMQConstants.java | 2 + .../component/springrabbit/RabbitMQEndpoint.java | 65 +++++++++++++++------- .../dsl/SpringRabbitmqComponentBuilderFactory.java | 18 ++++++ .../ROOT/pages/spring-rabbitmq-component.adoc | 44 +++++++++++++-- 10 files changed, 205 insertions(+), 34 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spring-rabbitmq-component.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spring-rabbitmq-component.adoc index 3a72093..93daff2 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spring-rabbitmq-component.adoc +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/spring-rabbitmq-component.adoc @@ -43,7 +43,7 @@ determines the exchange the queue will be bound to. == Options // component options: START -The Spring RabbitMQ component supports 19 options, which are listed below. +The Spring RabbitMQ component supports 20 options, which are listed below. @@ -66,6 +66,7 @@ The Spring RabbitMQ component supports 19 options, which are listed below. | *shutdownTimeout* (consumer) | The time to wait for workers in milliseconds after the container is stopped. If any workers are active when the shutdown signal comes they will be allowed to finish processing as long as they can finish within this timeout. | 5000 | long | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] | *autowiredEnabled* (advanced) | Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean +| *ignoreDeclarationExceptions* (advanced) | Switch on ignore exceptions such as mismatched properties when declaring | false | boolean | *messageConverter* (advanced) | To use a custom MessageConverter so you can be in control how to map to/from a org.springframework.amqp.core.Message. | | MessageConverter | *messagePropertiesConverter* (advanced) | To use a custom MessagePropertiesConverter so you can be in control how to map to/from a org.springframework.amqp.core.MessageProperties. | | MessagePropertiesConverter | *headerFilterStrategy* (filter) | To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. | | HeaderFilterStrategy @@ -161,6 +162,44 @@ in the endpoint uri, such as: to("spring-rabbitmq:default?routingKey=foo") ---- +== Auto declare exchanges, queues and bindings + +The Spring RabbitMQ will automatic necessary declare the elements and setup the binding between the exchange, queue and routing keys. +This can be turned off by setting `autoDeclare=false`. + +The elements can be configured using the multi-valued `args` option. + +For example to specify the queue as durable and exclusive, you can configure the endpoint uri with `arg.queue.durable=true&arg.queue.exclusive=true`. + +*Exchanges* + +[width="100%",cols="10%,10%,70%,10%",options="header",] +|===================================================================== +|Option |Type |Description|Default +| autoDelete | boolean | True if the server should delete the exchange when it is no longer in use (if all bindings are deleted). | false +| durable | boolean | A durable exchange will survive a server restart. | true +|===================================================================== + +You can also configure any additional `x-` arguments. +See details in the RabbitMQ documentation. + + +*Queues* + +[width="100%",cols="10%,10%,70%,10%",options="header",] +|===================================================================== +|Option |Type |Description|Default +| autoDelete | boolean | True if the server should delete the exchange when it is no longer in use (if all bindings are deleted). | false +| durable | boolean | A durable queue will survive a server restart. | false +| exclusive | boolean | Whether the queue is exclusive | false +| x-dead-letter-exchange | String | The name of the dead letter exchange. If none configured then the component configured value is used. | +| x-dead-letter-routing-key | String | The routing key for the dead letter exchange. If none configured then the component configured value is used. | +|===================================================================== + +You can also configure any additional `x-` arguments, such as the message time to live, via `x-message-ttl`, and many others. +See details in the RabbitMQ documentation. + + == Request / Reply Request and reply messaging is supported using https://www.rabbitmq.com/direct-reply-to.html[RabbitMQ direct reply-to]. @@ -186,9 +225,6 @@ from("spring-rabbitmq:cheese?queues=myqueue&routingKey=foo.bar") .transform(body().prepend("Hello ")); ---- -The Spring RabbitMQ will automatic necessary declare the elements and setup the binding between the exchange, queue and routing keys. -This can be turned off by setting `autoDeclare=false`. - == Reuse endpoint and send to different destinations computed at runtime If you need to send messages to a lot of different RabbitMQ exchanges, it diff --git a/components/camel-spring-rabbitmq/src/generated/java/org/apache/camel/component/springrabbit/RabbitMQComponentConfigurer.java b/components/camel-spring-rabbitmq/src/generated/java/org/apache/camel/component/springrabbit/RabbitMQComponentConfigurer.java index b4724f5..6bac8d0 100644 --- a/components/camel-spring-rabbitmq/src/generated/java/org/apache/camel/component/springrabbit/RabbitMQComponentConfigurer.java +++ b/components/camel-spring-rabbitmq/src/generated/java/org/apache/camel/component/springrabbit/RabbitMQComponentConfigurer.java @@ -45,6 +45,8 @@ public class RabbitMQComponentConfigurer extends PropertyConfigurerSupport imple case "errorHandler": target.setErrorHandler(property(camelContext, org.springframework.util.ErrorHandler.class, value)); return true; case "headerfilterstrategy": case "headerFilterStrategy": target.setHeaderFilterStrategy(property(camelContext, org.apache.camel.spi.HeaderFilterStrategy.class, value)); return true; + case "ignoredeclarationexceptions": + case "ignoreDeclarationExceptions": target.setIgnoreDeclarationExceptions(property(camelContext, boolean.class, value)); return true; case "lazystartproducer": case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; case "listenercontainerfactory": @@ -95,6 +97,8 @@ public class RabbitMQComponentConfigurer extends PropertyConfigurerSupport imple case "errorHandler": return org.springframework.util.ErrorHandler.class; case "headerfilterstrategy": case "headerFilterStrategy": return org.apache.camel.spi.HeaderFilterStrategy.class; + case "ignoredeclarationexceptions": + case "ignoreDeclarationExceptions": return boolean.class; case "lazystartproducer": case "lazyStartProducer": return boolean.class; case "listenercontainerfactory": @@ -141,6 +145,8 @@ public class RabbitMQComponentConfigurer extends PropertyConfigurerSupport imple case "errorHandler": return target.getErrorHandler(); case "headerfilterstrategy": case "headerFilterStrategy": return target.getHeaderFilterStrategy(); + case "ignoredeclarationexceptions": + case "ignoreDeclarationExceptions": return target.isIgnoreDeclarationExceptions(); case "lazystartproducer": case "lazyStartProducer": return target.isLazyStartProducer(); case "listenercontainerfactory": diff --git a/components/camel-spring-rabbitmq/src/generated/resources/org/apache/camel/component/springrabbit/spring-rabbitmq.json b/components/camel-spring-rabbitmq/src/generated/resources/org/apache/camel/component/springrabbit/spring-rabbitmq.json index 42290e8..33531aa 100644 --- a/components/camel-spring-rabbitmq/src/generated/resources/org/apache/camel/component/springrabbit/spring-rabbitmq.json +++ b/components/camel-spring-rabbitmq/src/generated/resources/org/apache/camel/component/springrabbit/spring-rabbitmq.json @@ -38,6 +38,7 @@ "shutdownTimeout": { "kind": "property", "displayName": "Shutdown Timeout", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "duration", "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "5000", "description": "The time to wait for workers in milliseconds after the container is stopped. If any workers are active when the shutdown signal comes they will be allowed to finish processing as long as they c [...] "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during star [...] "autowiredEnabled": { "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which t [...] + "ignoreDeclarationExceptions": { "kind": "property", "displayName": "Ignore Declaration Exceptions", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Switch on ignore exceptions such as mismatched properties when declaring" }, "messageConverter": { "kind": "property", "displayName": "Message Converter", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.springframework.amqp.support.converter.MessageConverter", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom MessageConverter so you can be in control how to map to\/from a org.springframework.amqp.core.Message." }, "messagePropertiesConverter": { "kind": "property", "displayName": "Message Properties Converter", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.springrabbit.MessagePropertiesConverter", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom MessagePropertiesConverter so you can be in control how to map to\/from a org.springframework.amqp.core.MessageProperties." }, "headerFilterStrategy": { "kind": "property", "displayName": "Header Filter Strategy", "group": "filter", "label": "filter", "required": false, "type": "object", "javaType": "org.apache.camel.spi.HeaderFilterStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message." } diff --git a/components/camel-spring-rabbitmq/src/main/docs/spring-rabbitmq-component.adoc b/components/camel-spring-rabbitmq/src/main/docs/spring-rabbitmq-component.adoc index 3a72093..93daff2 100644 --- a/components/camel-spring-rabbitmq/src/main/docs/spring-rabbitmq-component.adoc +++ b/components/camel-spring-rabbitmq/src/main/docs/spring-rabbitmq-component.adoc @@ -43,7 +43,7 @@ determines the exchange the queue will be bound to. == Options // component options: START -The Spring RabbitMQ component supports 19 options, which are listed below. +The Spring RabbitMQ component supports 20 options, which are listed below. @@ -66,6 +66,7 @@ The Spring RabbitMQ component supports 19 options, which are listed below. | *shutdownTimeout* (consumer) | The time to wait for workers in milliseconds after the container is stopped. If any workers are active when the shutdown signal comes they will be allowed to finish processing as long as they can finish within this timeout. | 5000 | long | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] | *autowiredEnabled* (advanced) | Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean +| *ignoreDeclarationExceptions* (advanced) | Switch on ignore exceptions such as mismatched properties when declaring | false | boolean | *messageConverter* (advanced) | To use a custom MessageConverter so you can be in control how to map to/from a org.springframework.amqp.core.Message. | | MessageConverter | *messagePropertiesConverter* (advanced) | To use a custom MessagePropertiesConverter so you can be in control how to map to/from a org.springframework.amqp.core.MessageProperties. | | MessagePropertiesConverter | *headerFilterStrategy* (filter) | To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. | | HeaderFilterStrategy @@ -161,6 +162,44 @@ in the endpoint uri, such as: to("spring-rabbitmq:default?routingKey=foo") ---- +== Auto declare exchanges, queues and bindings + +The Spring RabbitMQ will automatic necessary declare the elements and setup the binding between the exchange, queue and routing keys. +This can be turned off by setting `autoDeclare=false`. + +The elements can be configured using the multi-valued `args` option. + +For example to specify the queue as durable and exclusive, you can configure the endpoint uri with `arg.queue.durable=true&arg.queue.exclusive=true`. + +*Exchanges* + +[width="100%",cols="10%,10%,70%,10%",options="header",] +|===================================================================== +|Option |Type |Description|Default +| autoDelete | boolean | True if the server should delete the exchange when it is no longer in use (if all bindings are deleted). | false +| durable | boolean | A durable exchange will survive a server restart. | true +|===================================================================== + +You can also configure any additional `x-` arguments. +See details in the RabbitMQ documentation. + + +*Queues* + +[width="100%",cols="10%,10%,70%,10%",options="header",] +|===================================================================== +|Option |Type |Description|Default +| autoDelete | boolean | True if the server should delete the exchange when it is no longer in use (if all bindings are deleted). | false +| durable | boolean | A durable queue will survive a server restart. | false +| exclusive | boolean | Whether the queue is exclusive | false +| x-dead-letter-exchange | String | The name of the dead letter exchange. If none configured then the component configured value is used. | +| x-dead-letter-routing-key | String | The routing key for the dead letter exchange. If none configured then the component configured value is used. | +|===================================================================== + +You can also configure any additional `x-` arguments, such as the message time to live, via `x-message-ttl`, and many others. +See details in the RabbitMQ documentation. + + == Request / Reply Request and reply messaging is supported using https://www.rabbitmq.com/direct-reply-to.html[RabbitMQ direct reply-to]. @@ -186,9 +225,6 @@ from("spring-rabbitmq:cheese?queues=myqueue&routingKey=foo.bar") .transform(body().prepend("Hello ")); ---- -The Spring RabbitMQ will automatic necessary declare the elements and setup the binding between the exchange, queue and routing keys. -This can be turned off by setting `autoDeclare=false`. - == Reuse endpoint and send to different destinations computed at runtime If you need to send messages to a lot of different RabbitMQ exchanges, it diff --git a/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/DefaultListenerContainerFactory.java b/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/DefaultListenerContainerFactory.java index 902fa0d..c0486a1 100644 --- a/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/DefaultListenerContainerFactory.java +++ b/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/DefaultListenerContainerFactory.java @@ -37,8 +37,11 @@ public class DefaultListenerContainerFactory implements ListenerContainerFactory AmqpAdmin admin = endpoint.getComponent().getAmqpAdmin(); if (endpoint.isAutoDeclare() && admin == null) { - admin = new RabbitAdmin(endpoint.getConnectionFactory()); + RabbitAdmin ra = new RabbitAdmin(endpoint.getConnectionFactory()); + ra.setIgnoreDeclarationExceptions(endpoint.getComponent().isIgnoreDeclarationExceptions()); + admin = ra; } + listener.setAutoDeclare(endpoint.isAutoDeclare()); listener.setAmqpAdmin(admin); if (endpoint.getComponent().getErrorHandler() != null) { diff --git a/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/RabbitMQComponent.java b/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/RabbitMQComponent.java index 581d1b9c..7107bb5 100644 --- a/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/RabbitMQComponent.java +++ b/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/RabbitMQComponent.java @@ -86,6 +86,8 @@ public class RabbitMQComponent extends HeaderFilterStrategyComponent { @Metadata(label = "consumer,advanced", description = "To use a custom factory for creating and configuring ListenerContainer to be used by the consumer for receiving messages") private ListenerContainerFactory listenerContainerFactory = new DefaultListenerContainerFactory(); + @Metadata(label = "advanced", description = "Switch on ignore exceptions such as mismatched properties when declaring") + private boolean ignoreDeclarationExceptions; @Override protected void doInit() throws Exception { @@ -250,4 +252,12 @@ public class RabbitMQComponent extends HeaderFilterStrategyComponent { public void setListenerContainerFactory(ListenerContainerFactory listenerContainerFactory) { this.listenerContainerFactory = listenerContainerFactory; } + + public boolean isIgnoreDeclarationExceptions() { + return ignoreDeclarationExceptions; + } + + public void setIgnoreDeclarationExceptions(boolean ignoreDeclarationExceptions) { + this.ignoreDeclarationExceptions = ignoreDeclarationExceptions; + } } diff --git a/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/RabbitMQConstants.java b/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/RabbitMQConstants.java index 840709f..76a859d 100644 --- a/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/RabbitMQConstants.java +++ b/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/RabbitMQConstants.java @@ -27,8 +27,10 @@ public final class RabbitMQConstants { public static final String DEAD_LETTER_EXCHANGE = "x-dead-letter-exchange"; public static final String DEAD_LETTER_ROUTING_KEY = "x-dead-letter-routing-key"; public static final String MAX_LENGTH = "x-max-length"; + public static final String MAX_LENGTH_BYTES = "x-max-length-bytes"; public static final String MAX_PRIORITY = "x-max-priority"; public static final String MESSAGE_TTL = "x-message-ttl"; + public static final String DELIVERY_LIMIT = "x-delivery-limit"; public static final String EXPIRES = "x-expires"; public static final String SINGLE_ACTIVE_CONSUMER = "x-single-active-consumer"; diff --git a/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/RabbitMQEndpoint.java b/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/RabbitMQEndpoint.java index 9346716..829ac33 100644 --- a/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/RabbitMQEndpoint.java +++ b/components/camel-spring-rabbitmq/src/main/java/org/apache/camel/component/springrabbit/RabbitMQEndpoint.java @@ -432,6 +432,18 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint { } } + protected String parseArgsString(Map<String, Object> args, String key, String defaultValue) { + Object answer = args.remove(key); + if (answer == null) { + answer = defaultValue; + } + if (answer != null) { + return getCamelContext().getTypeConverter().convertTo(String.class, answer); + } else { + return null; + } + } + // TODO: auto-declare for producer only public void declareElements(AbstractMessageListenerContainer container) { @@ -515,6 +527,15 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint { if (exclusive) { qb.exclusive(); } + // setup DLQ + String dle = parseArgsString(args, "x-dead-letter-exchange", deadLetterExchange); + if (dle != null) { + qb.deadLetterExchange(dle); + } + String dlrk = parseArgsString(args, "x-dead-letter-routing-key", deadLetterRoutingKey); + if (dlrk != null) { + qb.deadLetterRoutingKey(dlrk); + } qb.withArguments(map); final Queue rabbitQueue = qb.build(); @@ -546,7 +567,6 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint { private void prepareDeadLetterQueueArgs(Map<String, Object> args) { if (deadLetterExchange != null) { args.put(RabbitMQConstants.DEAD_LETTER_EXCHANGE, deadLetterExchange); - if (deadLetterRoutingKey != null) { args.put(RabbitMQConstants.DEAD_LETTER_ROUTING_KEY, deadLetterRoutingKey); } @@ -555,30 +575,33 @@ public class RabbitMQEndpoint extends DefaultEndpoint implements AsyncEndpoint { private void prepareArgs(Map<String, Object> args) { // some arguments must be in numeric values so we need to fix this - Object queueLengthLimit = args.get(RabbitMQConstants.MAX_LENGTH); - if (queueLengthLimit instanceof String) { - args.put(RabbitMQConstants.MAX_LENGTH, Long.parseLong((String) queueLengthLimit)); + Object arg = args.get(RabbitMQConstants.MAX_LENGTH); + if (arg instanceof String) { + args.put(RabbitMQConstants.MAX_LENGTH, Long.parseLong((String) arg)); } - - Object queueMaxPriority = args.get(RabbitMQConstants.MAX_PRIORITY); - if (queueMaxPriority instanceof String) { - args.put(RabbitMQConstants.MAX_PRIORITY, Integer.parseInt((String) queueMaxPriority)); + arg = args.get(RabbitMQConstants.MAX_LENGTH_BYTES); + if (arg instanceof String) { + args.put(RabbitMQConstants.MAX_LENGTH_BYTES, Long.parseLong((String) arg)); } - - Object queueMessageTtl = args.get(RabbitMQConstants.MESSAGE_TTL); - if (queueMessageTtl instanceof String) { - args.put(RabbitMQConstants.MESSAGE_TTL, Long.parseLong((String) queueMessageTtl)); + arg = args.get(RabbitMQConstants.MAX_PRIORITY); + if (arg instanceof String) { + args.put(RabbitMQConstants.MAX_PRIORITY, Integer.parseInt((String) arg)); } - - Object queueExpiration = args.get(RabbitMQConstants.EXPIRES); - if (queueExpiration instanceof String) { - args.put(RabbitMQConstants.EXPIRES, Long.parseLong((String) queueExpiration)); + arg = args.get(RabbitMQConstants.DELIVERY_LIMIT); + if (arg instanceof String) { + args.put(RabbitMQConstants.DELIVERY_LIMIT, Integer.parseInt((String) arg)); } - - Object singleConsumer = args.get(RabbitMQConstants.SINGLE_ACTIVE_CONSUMER); - if (singleConsumer instanceof String) { - args.put(RabbitMQConstants.SINGLE_ACTIVE_CONSUMER, - Boolean.parseBoolean((String) singleConsumer)); + arg = args.get(RabbitMQConstants.MESSAGE_TTL); + if (arg instanceof String) { + args.put(RabbitMQConstants.MESSAGE_TTL, Long.parseLong((String) arg)); + } + arg = args.get(RabbitMQConstants.EXPIRES); + if (arg instanceof String) { + args.put(RabbitMQConstants.EXPIRES, Long.parseLong((String) arg)); + } + arg = args.get(RabbitMQConstants.SINGLE_ACTIVE_CONSUMER); + if (arg instanceof String) { + args.put(RabbitMQConstants.SINGLE_ACTIVE_CONSUMER, Boolean.parseBoolean((String) arg)); } } diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/SpringRabbitmqComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/SpringRabbitmqComponentBuilderFactory.java index 65ae914..30252d9 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/SpringRabbitmqComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/SpringRabbitmqComponentBuilderFactory.java @@ -335,6 +335,23 @@ public interface SpringRabbitmqComponentBuilderFactory { return this; } /** + * Switch on ignore exceptions such as mismatched properties when + * declaring. + * + * The option is a: <code>boolean</code> type. + * + * Default: false + * Group: advanced + * + * @param ignoreDeclarationExceptions the value to set + * @return the dsl builder + */ + default SpringRabbitmqComponentBuilder ignoreDeclarationExceptions( + boolean ignoreDeclarationExceptions) { + doSetProperty("ignoreDeclarationExceptions", ignoreDeclarationExceptions); + return this; + } + /** * To use a custom MessageConverter so you can be in control how to map * to/from a org.springframework.amqp.core.Message. * @@ -419,6 +436,7 @@ public interface SpringRabbitmqComponentBuilderFactory { case "shutdownTimeout": ((RabbitMQComponent) component).setShutdownTimeout((long) value); return true; case "lazyStartProducer": ((RabbitMQComponent) component).setLazyStartProducer((boolean) value); return true; case "autowiredEnabled": ((RabbitMQComponent) component).setAutowiredEnabled((boolean) value); return true; + case "ignoreDeclarationExceptions": ((RabbitMQComponent) component).setIgnoreDeclarationExceptions((boolean) value); return true; case "messageConverter": ((RabbitMQComponent) component).setMessageConverter((org.springframework.amqp.support.converter.MessageConverter) value); return true; case "messagePropertiesConverter": ((RabbitMQComponent) component).setMessagePropertiesConverter((org.apache.camel.component.springrabbit.MessagePropertiesConverter) value); return true; case "headerFilterStrategy": ((RabbitMQComponent) component).setHeaderFilterStrategy((org.apache.camel.spi.HeaderFilterStrategy) value); return true; diff --git a/docs/components/modules/ROOT/pages/spring-rabbitmq-component.adoc b/docs/components/modules/ROOT/pages/spring-rabbitmq-component.adoc index 3e4bb18..77e0efd 100644 --- a/docs/components/modules/ROOT/pages/spring-rabbitmq-component.adoc +++ b/docs/components/modules/ROOT/pages/spring-rabbitmq-component.adoc @@ -45,7 +45,7 @@ determines the exchange the queue will be bound to. == Options // component options: START -The Spring RabbitMQ component supports 19 options, which are listed below. +The Spring RabbitMQ component supports 20 options, which are listed below. @@ -68,6 +68,7 @@ The Spring RabbitMQ component supports 19 options, which are listed below. | *shutdownTimeout* (consumer) | The time to wait for workers in milliseconds after the container is stopped. If any workers are active when the shutdown signal comes they will be allowed to finish processing as long as they can finish within this timeout. | 5000 | long | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] | *autowiredEnabled* (advanced) | Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean +| *ignoreDeclarationExceptions* (advanced) | Switch on ignore exceptions such as mismatched properties when declaring | false | boolean | *messageConverter* (advanced) | To use a custom MessageConverter so you can be in control how to map to/from a org.springframework.amqp.core.Message. | | MessageConverter | *messagePropertiesConverter* (advanced) | To use a custom MessagePropertiesConverter so you can be in control how to map to/from a org.springframework.amqp.core.MessageProperties. | | MessagePropertiesConverter | *headerFilterStrategy* (filter) | To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter header to and from Camel message. | | HeaderFilterStrategy @@ -163,6 +164,44 @@ in the endpoint uri, such as: to("spring-rabbitmq:default?routingKey=foo") ---- +== Auto declare exchanges, queues and bindings + +The Spring RabbitMQ will automatic necessary declare the elements and setup the binding between the exchange, queue and routing keys. +This can be turned off by setting `autoDeclare=false`. + +The elements can be configured using the multi-valued `args` option. + +For example to specify the queue as durable and exclusive, you can configure the endpoint uri with `arg.queue.durable=true&arg.queue.exclusive=true`. + +*Exchanges* + +[width="100%",cols="10%,10%,70%,10%",options="header",] +|===================================================================== +|Option |Type |Description|Default +| autoDelete | boolean | True if the server should delete the exchange when it is no longer in use (if all bindings are deleted). | false +| durable | boolean | A durable exchange will survive a server restart. | true +|===================================================================== + +You can also configure any additional `x-` arguments. +See details in the RabbitMQ documentation. + + +*Queues* + +[width="100%",cols="10%,10%,70%,10%",options="header",] +|===================================================================== +|Option |Type |Description|Default +| autoDelete | boolean | True if the server should delete the exchange when it is no longer in use (if all bindings are deleted). | false +| durable | boolean | A durable queue will survive a server restart. | false +| exclusive | boolean | Whether the queue is exclusive | false +| x-dead-letter-exchange | String | The name of the dead letter exchange. If none configured then the component configured value is used. | +| x-dead-letter-routing-key | String | The routing key for the dead letter exchange. If none configured then the component configured value is used. | +|===================================================================== + +You can also configure any additional `x-` arguments, such as the message time to live, via `x-message-ttl`, and many others. +See details in the RabbitMQ documentation. + + == Request / Reply Request and reply messaging is supported using https://www.rabbitmq.com/direct-reply-to.html[RabbitMQ direct reply-to]. @@ -188,9 +227,6 @@ from("spring-rabbitmq:cheese?queues=myqueue&routingKey=foo.bar") .transform(body().prepend("Hello ")); ---- -The Spring RabbitMQ will automatic necessary declare the elements and setup the binding between the exchange, queue and routing keys. -This can be turned off by setting `autoDeclare=false`. - == Reuse endpoint and send to different destinations computed at runtime If you need to send messages to a lot of different RabbitMQ exchanges, it