Repository navigation
Upgraded to version 1.0.0 of the Solace cloud connector, added discussion of HA. #17
Changes from all commits
848f42b
efeeead
a215c9d
6512204
a70436a
83a7513
b6d62ef
f37c8af
ca68c2b
6ff051b
dd5e7de
5b3905d
fba5ff4
7a7df8e
f347576
02bb150
320dbc7
89cb009
77bca79
9590cc9
c23db37
07c0748
3375643
61a163e
2ddecce
b3558d8
797c095
19c4293
0e6569c
90ada31
d010d4b
041af53
1fbd779
fd2e485
0029972
0cdfc00
3e0c12e
a864fb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,7 +91,7 @@ The Pivotal Cloud Foundry environment exposes any bound Service Instances in a J | |
| "clientPassword": "bb90fcb0-6c83-4a10-bafa-3ec225bbfc08", | ||
| "msgVpnName": "v005", | ||
| (...) | ||
| "smfHost": "tcp://192.168.132.14:7000", | ||
| "smfHosts": [ "tcp://192.168.132.14:7000" ], | ||
| (...) | ||
| } | ||
| } | ||
|
|
@@ -153,8 +153,14 @@ logger.info("Solace client initializing and using Credentials: " + solaceCredent | |
| Once the credentials are extracted, you can create and then connect the Solace Session in the conventional way as outlined in the [Publish/Subscribe tutorial]({{ site.links-pubsub-tutorial }}){:target="_top"}. You set the JCSMP properties and then use the `JCSMPFactory` to create a `Session`: | ||
|
|
||
| ```java | ||
|
|
||
| // The host property is in a json array. Two hosts are provided in a High Availability | ||
| // environment, one for the primary router and one for the backup. | ||
| JSONArray hostsArray = solaceCredentials.getJSONArray("smfHosts"); | ||
| String host = hostsArray.getString(0); | ||
|
|
||
| final JCSMPProperties properties = new JCSMPProperties(); | ||
| properties.setProperty(JCSMPProperties.HOST, solaceCredentials.getString("smfHost")); | ||
| properties.setProperty(JCSMPProperties.HOST, host); | ||
| properties.setProperty(JCSMPProperties.VPN_NAME, solaceCredentials.getString("msgVpnName")); | ||
| properties.setProperty(JCSMPProperties.USERNAME, solaceCredentials.getString("clientUsername")); | ||
| properties.setProperty(JCSMPProperties.PASSWORD, solaceCredentials.getString("clientPassword")); | ||
|
|
@@ -291,7 +297,7 @@ export APP_URL=`cf apps | grep $APP_NAME | grep started | awk '{ print $6}'` | |
| echo "The application URL is: ${APP_URL}" | ||
| ``` | ||
|
|
||
| To demonstrate the application we will make the application send a message to itself. Then we will read the message back to confirm the successful delivery of the message : | ||
| To demonstrate the application we will make the application send a message to itself. Then we will read the message back to confirm the successful delivery of the message: | ||
|
|
||
| ``` | ||
| # Subscribes the application to the topic "test" | ||
|
|
@@ -303,3 +309,43 @@ curl -X POST -H "Content-Type: application/json;charset=UTF-8" -d '{"topic": "te | |
| # The message should have been asynchronously received by the application. Check that the message was indeed received: | ||
| curl -X GET http://$APP_URL/message | ||
| ``` | ||
| ## High Availability | ||
|
|
||
| Solace provides the option to set up High Availability configurations, where each message router has a backup. To use this in Cloud Foundry you need to create a service of type medium-ha or large-ha, for example: | ||
|
|
||
| ``` | ||
| cf create-service solace-messaging medium-ha solace-messaging-sample-instance | ||
| ``` | ||
|
|
||
| The Solace Java API automatically switches to the backup connection if it loses the connection to the primary router. | ||
|
|
||
| When using a High Availability service, the environment provided to the applications contains two connection urls rather than one. The first is the primary router and the second is the backup, for example: | ||
|
|
||
| ``` | ||
| "smfHosts": [ "tcp://192.168.101.16:7000", "tcp://192.168.101.17:7000" ] | ||
| ``` | ||
|
|
||
| In order to provide both hosts to the Solace Java API, you need to create a string containing a comma-separated list of the two hosts: | ||
|
|
||
| ``` | ||
| // The host property is in a json array. Two hosts are provided in a High Availability | ||
| // environment, one for the primary router and one for the backup. | ||
| JSONArray hostsArray = solaceCredentials.getJSONArray("smfHosts"); | ||
| String primary = hostsArray.getString(0); | ||
| String backup = hostsArray.getString(1); | ||
| String hosts = String.join(",", primary, backup); | ||
| properties.setProperty(JCSMPProperties.HOST, hosts); | ||
| ``` | ||
| When you do the Spring Cloud tutorial, you will see that the Solace Spring Cloud Connector takes care of this for you. | ||
|
|
||
| Please consult the [Best Practices]({{ site.links-best-practices }}){:target="_top"} page, particularly the section named Replication Best Practices. | ||
|
|
||
| As described in that document, when using High Availability it is recommended to set the following configuration: | ||
|
|
||
| ``` | ||
| JCSMPProperties properties = new JCSMPProperties(); | ||
| JCSMPChannelProperties cp = (JCSMPChannelProperties) properties | ||
| .getProperty(JCSMPProperties.CLIENT_CHANNEL_PROPERTIES); | ||
| cp.setReconnectRetries(-1); // try reconnecting forever | ||
| ``` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use best practice recommendations here and not forever. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,8 +168,6 @@ curl -X GET http://$APP_URL/message | |
|
|
||
| ## Common Problems | ||
|
|
||
| ### JCSMPTransportException | ||
|
|
||
| If you see: | ||
|
|
||
| ``` | ||
|
|
@@ -178,14 +176,14 @@ JCSMPTransportException: Error communicating with the router, ConnectException: | |
|
|
||
| this can happen if a TLS server certificate was not configured in the Solace Messaging for PCF tile in which case the Solace Message Router will reject incoming TLS connections. | ||
|
|
||
| ### CertificateException | ||
| >>>>>>> 2ddecceb096c1c345139b6b2f2bfb47b3348e923 | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merge issue. Please fix. |
||
| If you see: | ||
| ``` | ||
| CertificateException: Path does not chain with any of the trust anchors | ||
| ``` | ||
|
|
||
| it is because the application could not validate the certificate it received from the Solace Message Router. This can happen when you install a self-signed certificate on the Solace Message Router, but didn't package it with the app, or didn't set INSTALL_CERTIFICATE to true in the sample. | ||
| it is because the application could not validate the certificate it received from the server. This can happen when you install a self-signed certificate on the router, but didn't package it with the app, or didn't set INSTALL_CERTIFICATE to true. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have reverted some text here which is not correct. |
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ jar { | |
|
|
||
| repositories { | ||
| mavenCentral() | ||
| mavenLocal() | ||
| } | ||
|
|
||
| dependencies { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,11 +125,26 @@ public void init() { | |
|
|
||
| logger.info("Solace client initializing and using Credentials: " + solaceCredentials.toString(2)); | ||
|
|
||
|
|
||
| // The host property is in a json array. Two hosts are provided in a High Availability environment, | ||
| // one for the primary router and one for the backup. | ||
| JSONArray hostsArray = solaceCredentials.getJSONArray("smfHosts"); | ||
| String host = hostsArray.getString(0); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks broken for HA. |
||
| // If using high availability, uncomment these lines - the JCSMP library accepts a comma-separated list of 2 hosts: | ||
| //String backup = hostsArray.getString(1); | ||
| //host = String.join(",", host, backup); | ||
|
|
||
| final JCSMPProperties properties = new JCSMPProperties(); | ||
| properties.setProperty(JCSMPProperties.HOST, solaceCredentials.getString("smfHost")); | ||
| properties.setProperty(JCSMPProperties.HOST, host); | ||
| properties.setProperty(JCSMPProperties.VPN_NAME, solaceCredentials.getString("msgVpnName")); | ||
| properties.setProperty(JCSMPProperties.USERNAME, solaceCredentials.getString("clientUsername")); | ||
| properties.setProperty(JCSMPProperties.PASSWORD, solaceCredentials.getString("clientPassword")); | ||
|
|
||
| // If using High Availability, uncomment these lines: | ||
| // JCSMPChannelProperties channelProperties = (JCSMPChannelProperties) properties | ||
| // .getProperty(JCSMPProperties.CLIENT_CHANNEL_PROPERTIES); | ||
| // channelProperties.setReconnectRetries(-1); | ||
|
|
||
| try { | ||
| session = JCSMPFactory.onlyInstance().createSession(properties); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,16 +154,20 @@ public void init() { | |
| logger.info("Solace client initializing and using SolaceMessagingInfo: " + solaceMessagingServiceInfo); | ||
|
|
||
| final JCSMPProperties properties = new JCSMPProperties(); | ||
| properties.setProperty(JCSMPProperties.HOST, solaceMessagingServiceInfo.getSmfTlsHost()); | ||
| properties.setProperty(JCSMPProperties.HOST, solaceMessagingServiceInfo.getSmfHost()); | ||
| properties.setProperty(JCSMPProperties.VPN_NAME, solaceMessagingServiceInfo.getMsgVpnName()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks broken for TLS. |
||
| properties.setProperty(JCSMPProperties.USERNAME, solaceMessagingServiceInfo.getClientUsername()); | ||
| properties.setProperty(JCSMPProperties.PASSWORD, solaceMessagingServiceInfo.getClientPassword()); | ||
|
|
||
| properties.setProperty(JCSMPProperties.SSL_VALIDATE_CERTIFICATE, true); | ||
| properties.setProperty(JCSMPProperties.SSL_VALIDATE_CERTIFICATE_DATE, true); | ||
| properties.setProperty(JCSMPProperties.SSL_TRUST_STORE, TRUST_STORE); | ||
| properties.setProperty(JCSMPProperties.SSL_TRUST_STORE_PASSWORD, TRUST_STORE_PASSWORD); | ||
|
|
||
| // If using High Availability, uncomment these lines: | ||
| // JCSMPChannelProperties channelProperties = (JCSMPChannelProperties) properties | ||
| // .getProperty(JCSMPProperties.CLIENT_CHANNEL_PROPERTIES); | ||
| // channelProperties.setReconnectRetries(-1); | ||
| try { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix so this follows best practices for reconnecting in an HA environment. |
||
| session = JCSMPFactory.onlyInstance().createSession(properties); | ||
| session.connect(); | ||
|
|
@@ -331,6 +335,7 @@ private static void importCertificate() throws Exception { | |
| DataInputStream dis = new DataInputStream(fis); | ||
| byte[] bytes = new byte[dis.available()]; | ||
| dis.readFully(bytes); | ||
| dis.close(); | ||
| ByteArrayInputStream certstream = new ByteArrayInputStream(bytes); | ||
|
|
||
| // This takes that Byte Array and creates a certificate out of it. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,6 +123,11 @@ public void init() { | |
| properties.setProperty(JCSMPProperties.USERNAME, solaceMessagingServiceInfo.getClientUsername()); | ||
| properties.setProperty(JCSMPProperties.PASSWORD, solaceMessagingServiceInfo.getClientPassword()); | ||
|
|
||
| // If using High Availability, uncomment these lines: | ||
| // JCSMPChannelProperties channelProperties = (JCSMPChannelProperties) properties | ||
| // .getProperty(JCSMPProperties.CLIENT_CHANNEL_PROPERTIES); | ||
| // channelProperties.setReconnectRetries(-1); | ||
|
|
||
| try { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please follow HA best practices. |
||
| session = JCSMPFactory.onlyInstance().createSession(properties); | ||
| session.connect(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Point us to an architectural overview of HA in the PCF Tile docs with picture.