Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,36 @@

package com.solace.samples.cloudfoundry.javaapp.controller;

import com.solace.samples.cloudfoundry.javaapp.model.SimpleMessage;
import com.solace.samples.cloudfoundry.javaapp.model.SimpleSubscription;
import com.solacesystems.jcsmp.*;
import java.util.concurrent.atomic.AtomicInteger;

import javax.annotation.PostConstruct;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.concurrent.atomic.AtomicInteger;
import com.solace.samples.cloudfoundry.javaapp.model.SimpleMessage;
import com.solace.samples.cloudfoundry.javaapp.model.SimpleSubscription;
import com.solacesystems.jcsmp.BytesXMLMessage;
import com.solacesystems.jcsmp.JCSMPChannelProperties;
import com.solacesystems.jcsmp.JCSMPException;
import com.solacesystems.jcsmp.JCSMPFactory;
import com.solacesystems.jcsmp.JCSMPProperties;
import com.solacesystems.jcsmp.JCSMPSession;
import com.solacesystems.jcsmp.JCSMPStreamingPublishEventHandler;
import com.solacesystems.jcsmp.TextMessage;
import com.solacesystems.jcsmp.Topic;
import com.solacesystems.jcsmp.XMLMessageConsumer;
import com.solacesystems.jcsmp.XMLMessageListener;
import com.solacesystems.jcsmp.XMLMessageProducer;

@RestController
public class SolaceController {
Expand All @@ -41,6 +58,16 @@ public class SolaceController {
private JCSMPSession session;
private XMLMessageProducer producer;
private TextMessage lastReceivedMessage;

// Reconnect properties for High Availability
@Value("${SOLACE_CHANNEL_PROPERTIES_CONNECTION_RETRIES:1}")
private int connectRetries;
@Value("${SOLACE_CHANNEL_PROPERTIES_RECONNECT_RETRIES:5}")
private int reconnectRetries;
@Value("${SOLACE_CHANNEL_PROPERTIES_RECONNECT_RETRY_WAIT_IN_MILLIS:3000}")
private int reconnectRetryWaitInMillis;
@Value("${SOLACE_CHANNEL_PROPERTIES_CONNECT_RETRIES_PER_HOST:20}")
private int connectRetriesPerHost;

// Stats
private final AtomicInteger numMessagesReceived = new AtomicInteger();
Expand Down Expand Up @@ -142,7 +169,12 @@ public void init() {
host += newHostEntry;
}

logger.info("Using host " + host);
logger.info("Using host " + host);
logger.info("connectRetries " + connectRetries);
logger.info("reconnectRetries " + reconnectRetries);
logger.info("reconnectRetryWaitInMillis " + reconnectRetryWaitInMillis);
logger.info("connectRetriesPerHost " + connectRetriesPerHost);

properties.setProperty(JCSMPProperties.HOST, host);

// Must be using HA to have more than 1 host.
Expand All @@ -151,10 +183,10 @@ public void init() {
// A Sample for High Availability automatic reconnects.
JCSMPChannelProperties channelProperties = (JCSMPChannelProperties) properties
.getProperty(JCSMPProperties.CLIENT_CHANNEL_PROPERTIES);
channelProperties.setConnectRetries(1);
channelProperties.setReconnectRetries(5);
channelProperties.setReconnectRetryWaitInMillis(3000);
channelProperties.setConnectRetriesPerHost(20);
channelProperties.setConnectRetries(connectRetries);
channelProperties.setReconnectRetries(reconnectRetries);
channelProperties.setReconnectRetryWaitInMillis(reconnectRetryWaitInMillis);
channelProperties.setConnectRetriesPerHost(connectRetriesPerHost);
}

properties.setProperty(JCSMPProperties.VPN_NAME, solaceCredentials.getString("msgVpnName"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.Cloud;
import org.springframework.cloud.CloudFactory;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -79,6 +80,16 @@ public class SolaceController {
// Standard default password for the trust store
private static final String TRUST_STORE_PASSWORD = "changeit";

// Reconnect properties for High Availability
@Value("${SOLACE_CHANNEL_PROPERTIES_CONNECTION_RETRIES:1}")
private int connectRetries;
@Value("${SOLACE_CHANNEL_PROPERTIES_RECONNECT_RETRIES:5}")
private int reconnectRetries;
@Value("${SOLACE_CHANNEL_PROPERTIES_RECONNECT_RETRY_WAIT_IN_MILLIS:3000}")
private int reconnectRetryWaitInMillis;
@Value("${SOLACE_CHANNEL_PROPERTIES_CONNECT_RETRIES_PER_HOST:20}")
private int connectRetriesPerHost;

private JCSMPSession session;
private XMLMessageProducer producer;
private TextMessage lastReceivedMessage;
Expand Down Expand Up @@ -173,10 +184,10 @@ public void init() {
// Recommended values for High Availability automatic reconnects.
JCSMPChannelProperties channelProperties = (JCSMPChannelProperties) properties
.getProperty(JCSMPProperties.CLIENT_CHANNEL_PROPERTIES);
channelProperties.setConnectRetries(1);
channelProperties.setReconnectRetries(5);
channelProperties.setReconnectRetryWaitInMillis(3000);
channelProperties.setConnectRetriesPerHost(20);
channelProperties.setConnectRetries(connectRetries);
channelProperties.setReconnectRetries(reconnectRetries);
channelProperties.setReconnectRetryWaitInMillis(reconnectRetryWaitInMillis);
channelProperties.setConnectRetriesPerHost(connectRetriesPerHost);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.Cloud;
import org.springframework.cloud.CloudFactory;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -60,6 +61,16 @@ public class SolaceController {
private XMLMessageProducer producer;
private TextMessage lastReceivedMessage;

// Reconnect properties for High Availability
@Value("${SOLACE_CHANNEL_PROPERTIES_CONNECTION_RETRIES:1}")
private int connectRetries;
@Value("${SOLACE_CHANNEL_PROPERTIES_RECONNECT_RETRIES:5}")
private int reconnectRetries;
@Value("${SOLACE_CHANNEL_PROPERTIES_RECONNECT_RETRY_WAIT_IN_MILLIS:3000}")
private int reconnectRetryWaitInMillis;
@Value("${SOLACE_CHANNEL_PROPERTIES_CONNECT_RETRIES_PER_HOST:20}")
private int connectRetriesPerHost;

// Stats
private final AtomicInteger numMessagesReceived = new AtomicInteger();
private final AtomicInteger numMessagesSent = new AtomicInteger();
Expand Down Expand Up @@ -132,10 +143,10 @@ public void init() {
// Recommended values for High Availability automatic reconnects.
JCSMPChannelProperties channelProperties = (JCSMPChannelProperties) properties
.getProperty(JCSMPProperties.CLIENT_CHANNEL_PROPERTIES);
channelProperties.setConnectRetries(1);
channelProperties.setReconnectRetries(5);
channelProperties.setReconnectRetryWaitInMillis(3000);
channelProperties.setConnectRetriesPerHost(20);
channelProperties.setConnectRetries(connectRetries);
channelProperties.setReconnectRetries(reconnectRetries);
channelProperties.setReconnectRetryWaitInMillis(reconnectRetryWaitInMillis);
channelProperties.setConnectRetriesPerHost(connectRetriesPerHost);
}

try {
Expand Down