You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/12/04 09:12:39 UTC

[camel] 03/04: CAMEL-14253: camel-nats - Configure brokers on component level

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 725fed6e733ccf756217a4ddbbf547d9fa7600bd
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Dec 4 10:10:31 2019 +0100

    CAMEL-14253: camel-nats - Configure brokers on component level
---
 .../camel-nats/src/main/docs/nats-component.adoc   | 72 +++++++++++++++++-----
 .../camel/component/nats/NatsAuthTestSupport.java  |  2 +-
 .../component/nats/NatsAuthTokenTestSupport.java   |  2 +-
 .../camel/component/nats/NatsTestSupport.java      |  2 +-
 .../modules/ROOT/pages/nats-component.adoc         | 72 +++++++++++++++++-----
 5 files changed, 117 insertions(+), 33 deletions(-)

diff --git a/components/camel-nats/src/main/docs/nats-component.adoc b/components/camel-nats/src/main/docs/nats-component.adoc
index 8ee8984..bc340ac 100644
--- a/components/camel-nats/src/main/docs/nats-component.adoc
+++ b/components/camel-nats/src/main/docs/nats-component.adoc
@@ -26,10 +26,10 @@ their `pom.xml` for this component.
 
 [source,java]
 ----------------------
-nats:servers[?options]
+nats:topic[?options]
 ----------------------
 
-Where *servers* represents the list of NATS servers.
+Where *topic* is the topic name
 
 == Options
 
@@ -125,7 +125,7 @@ When using Spring Boot make sure to use the following Maven dependency to have s
 ----
 
 
-The component supports 5 options, which are listed below.
+The component supports 6 options, which are listed below.
 
 
 
@@ -136,13 +136,51 @@ The component supports 5 options, which are listed below.
 | *camel.component.nats.bridge-error-handler* | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | Boolean
 | *camel.component.nats.enabled* | Whether to enable auto configuration of the nats component. This is enabled by default. |  | Boolean
 | *camel.component.nats.lazy-start-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  [...]
+| *camel.component.nats.servers* | URLs to one or more NAT servers. Use comma to separate URLs when specifying multiple servers. |  | String
 | *camel.component.nats.use-global-ssl-context-parameters* | Enable usage of global SSL context parameters. | false | Boolean
 |===
 // spring-boot-auto-configure options: END
 
 
+== Configuring servers
 
+You configure the NATS servers on either the component or the endpoint.
 
+For example to configure this once on the component you can do:
+
+[source,java]
+----
+NatsComponent nats = context.getComponent("nats", NatsComponent.class);
+nats.setServers("someserver:4222,someotherserver:42222");
+----
+
+Notice how you can specify multiple servers separated by comma.
+
+Or you can specify the servers in the endpoint URI
+
+[source,java]
+----
+from("direct:send").to("nats:test?servers=localhost:4222");
+----
+
+The endpoint configuration will override any server configuration on the component level.
+
+=== Configuring username and password or token
+
+You can specify username and password for the servers in the server URLs,
+where its `username:password@url`, or `token@url` etc:
+
+[source,java]
+----
+NatsComponent nats = context.getComponent("nats", NatsComponent.class);
+nats.setServers("scott:tiger@someserver:4222,superman:123@someotherserver:42222");
+----
+
+If you are using Camel Main or Spring Boot you can configure the server urls in the `application.properties` file
+[source,properties]
+----
+camel.component.nats.servers=scott:tiger@someserver:4222,superman:123@someotherserver:42222
+----
 
 == Headers
 
@@ -167,27 +205,31 @@ The consumer will when routing the message is complete, send back the message as
 *Producer example:*
 
 [source,java]
------------------------------------------------------------
-from("direct:send").to("nats://localhost:4222?topic=test");
------------------------------------------------------------
+----
+from("direct:send")
+  .to("nats:mytopic");
+----
 
 In case of using Authorization you can directly specify your credentials in the server URL
 
 [source,java]
------------------------------------------------------------
-from("direct:send").to("nats://username:password@localhost:4222?topic=test");
------------------------------------------------------------
+----
+from("direct:send")
+  .to("nats:mytopic?servers=username:password@localhost:4222");
+----
 
 or your token
 
 [source,java]
------------------------------------------------------------
-from("direct:send").to("nats://token@localhost:4222?topic=test");
------------------------------------------------------------
+----
+from("direct:send")
+  .to("nats:mytopic?servers=token@localhost:4222);
+----
 
 *Consumer example:*
 
 [source,java]
-----------------------------------------------------------------------------------------
-from("nats://localhost:4222?topic=test&maxMessages=5&queueName=test").to("mock:result");
-----------------------------------------------------------------------------------------
+----
+from("nats:mytopic?maxMessages=5&queueName=myqueue")
+  .to("mock:result");
+----
diff --git a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTestSupport.java b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTestSupport.java
index cfdc929..f7b9549 100644
--- a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTestSupport.java
+++ b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTestSupport.java
@@ -23,7 +23,7 @@ import org.testcontainers.containers.GenericContainer;
 
 public class NatsAuthTestSupport extends ContainerAwareTestSupport {
 
-    public static final String CONTAINER_IMAGE = "nats:2.1.0";
+    public static final String CONTAINER_IMAGE = "nats:2.1.2";
     public static final String CONTAINER_NAME = "nats-auth";
     public static final String USERNAME = "admin";
     public static final String PASSWORD = "password";
diff --git a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTokenTestSupport.java b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTokenTestSupport.java
index 2a19a28..23c68e8 100644
--- a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTokenTestSupport.java
+++ b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsAuthTokenTestSupport.java
@@ -23,7 +23,7 @@ import org.testcontainers.containers.GenericContainer;
 
 public class NatsAuthTokenTestSupport extends ContainerAwareTestSupport {
 
-    public static final String CONTAINER_IMAGE = "nats:2.1.0";
+    public static final String CONTAINER_IMAGE = "nats:2.1.2";
     public static final String CONTAINER_NAME = "nats-auth-token";
     public static final String TOKEN = "!admin23456";
     
diff --git a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsTestSupport.java b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsTestSupport.java
index e13affd..3352859 100644
--- a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsTestSupport.java
+++ b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsTestSupport.java
@@ -23,7 +23,7 @@ import org.testcontainers.containers.GenericContainer;
 
 public class NatsTestSupport extends ContainerAwareTestSupport {
 
-    public static final String CONTAINER_IMAGE = "nats:2.1.0";
+    public static final String CONTAINER_IMAGE = "nats:2.1.2";
     public static final String CONTAINER_NAME = "nats";
     
     @Override
diff --git a/docs/components/modules/ROOT/pages/nats-component.adoc b/docs/components/modules/ROOT/pages/nats-component.adoc
index 1533e4c..746faaa 100644
--- a/docs/components/modules/ROOT/pages/nats-component.adoc
+++ b/docs/components/modules/ROOT/pages/nats-component.adoc
@@ -27,10 +27,10 @@ their `pom.xml` for this component.
 
 [source,java]
 ----------------------
-nats:servers[?options]
+nats:topic[?options]
 ----------------------
 
-Where *servers* represents the list of NATS servers.
+Where *topic* is the topic name
 
 == Options
 
@@ -126,7 +126,7 @@ When using Spring Boot make sure to use the following Maven dependency to have s
 ----
 
 
-The component supports 5 options, which are listed below.
+The component supports 6 options, which are listed below.
 
 
 
@@ -137,13 +137,51 @@ The component supports 5 options, which are listed below.
 | *camel.component.nats.bridge-error-handler* | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | Boolean
 | *camel.component.nats.enabled* | Whether to enable auto configuration of the nats component. This is enabled by default. |  | Boolean
 | *camel.component.nats.lazy-start-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  [...]
+| *camel.component.nats.servers* | URLs to one or more NAT servers. Use comma to separate URLs when specifying multiple servers. |  | String
 | *camel.component.nats.use-global-ssl-context-parameters* | Enable usage of global SSL context parameters. | false | Boolean
 |===
 // spring-boot-auto-configure options: END
 
 
+== Configuring servers
 
+You configure the NATS servers on either the component or the endpoint.
 
+For example to configure this once on the component you can do:
+
+[source,java]
+----
+NatsComponent nats = context.getComponent("nats", NatsComponent.class);
+nats.setServers("someserver:4222,someotherserver:42222");
+----
+
+Notice how you can specify multiple servers separated by comma.
+
+Or you can specify the servers in the endpoint URI
+
+[source,java]
+----
+from("direct:send").to("nats:test?servers=localhost:4222");
+----
+
+The endpoint configuration will override any server configuration on the component level.
+
+=== Configuring username and password or token
+
+You can specify username and password for the servers in the server URLs,
+where its `username:password@url`, or `token@url` etc:
+
+[source,java]
+----
+NatsComponent nats = context.getComponent("nats", NatsComponent.class);
+nats.setServers("scott:tiger@someserver:4222,superman:123@someotherserver:42222");
+----
+
+If you are using Camel Main or Spring Boot you can configure the server urls in the `application.properties` file
+[source,properties]
+----
+camel.component.nats.servers=scott:tiger@someserver:4222,superman:123@someotherserver:42222
+----
 
 == Headers
 
@@ -168,27 +206,31 @@ The consumer will when routing the message is complete, send back the message as
 *Producer example:*
 
 [source,java]
------------------------------------------------------------
-from("direct:send").to("nats://localhost:4222?topic=test");
------------------------------------------------------------
+----
+from("direct:send")
+  .to("nats:mytopic");
+----
 
 In case of using Authorization you can directly specify your credentials in the server URL
 
 [source,java]
------------------------------------------------------------
-from("direct:send").to("nats://username:password@localhost:4222?topic=test");
------------------------------------------------------------
+----
+from("direct:send")
+  .to("nats:mytopic?servers=username:password@localhost:4222");
+----
 
 or your token
 
 [source,java]
------------------------------------------------------------
-from("direct:send").to("nats://token@localhost:4222?topic=test");
------------------------------------------------------------
+----
+from("direct:send")
+  .to("nats:mytopic?servers=token@localhost:4222);
+----
 
 *Consumer example:*
 
 [source,java]
-----------------------------------------------------------------------------------------
-from("nats://localhost:4222?topic=test&maxMessages=5&queueName=test").to("mock:result");
-----------------------------------------------------------------------------------------
+----
+from("nats:mytopic?maxMessages=5&queueName=myqueue")
+  .to("mock:result");
+----