Re: AMQP 1.0 Qpid JMS and an Issue with Failover/Reconnect

2016-03-23 Thread Timothy Bish

On 03/23/2016 08:56 AM, Aleks Balaban wrote:

Tim,

Thx, good to know that the failover works! Obviously I've been doing 
something wrong. Well, as you requested here is my JMS/AMQP client 
source (I have removed the SSL initialization part used for amqps 
conncetion ):





Your code relies on there being at least one non-daemon thread in 
existence at all time to prevent the main app from shutting down which 
will not always be the case as the code is currently written. Because of 
this your shutdown hook is being triggered and the shutdown of the 
connection and its underlying resources is occurring leading to the logs 
that you are seeing.



Connection URI:
connectionfactory.nm = 
failover:(amqps://somedomain.com:5671)?failover.reconnectDelay=2000=1



Source code:

public class TestClient implements Runnable {

private static final Logger logger = 
Logger.getLogger(TestClient.class.getName());

private static Connection connection;

public static void main(String[] args) {

org.apache.log4j.PropertyConfigurator.configure("./log4j.properties");

initSSL();

new Thread(new TestClient()).start();

Runtime.getRuntime().addShutdownHook(new Thread(() -> {

logger.info("Shutting down...");

try {
if (connection != null) {
connection.close();
}
} catch (JMSException e) {
logger.warning(e.getMessage());
}
}));
}

@Override
public void run() {

try {
Properties properties = new Properties();

if (System.getProperty("nmclient.configuration") == null) {
File jarPath = new 
File(TestClient.class.getProtectionDomain().getCodeSource().getLocation().getPath());

String propertiesPath = jarPath.getParent();
properties.load(new FileInputStream(propertiesPath + 
"/config.properties"));

} else {
properties.load(new 
FileInputStream(System.getProperty("nmclient.configuration")));

}

Context context = new InitialContext(properties);
ConnectionFactory connectionFactory = (ConnectionFactory) 
context.lookup("nm");


connection = connectionFactory.createConnection();

connection.setExceptionListener((final JMSException e) -> {
logger.log(Level.SEVERE, null, e);
});

Session consumerSession = connection.createSession(false, 
Session.CLIENT_ACKNOWLEDGE);

Queue queueEaup = (Queue) context.lookup("eaup");
MessageConsumer messageConsumer = 
consumerSession.createConsumer(queueEaup);


messageConsumer.setMessageListener((final Message message) 
-> {

try {
if (message instanceof TextMessage) {

TextMessage payload = (TextMessage) message;
logger.info(payload.getText());
}
message.acknowledge();
} catch (Exception e) {
logger.log(Level.SEVERE, null, e);
}
});

connection.start();

} catch (IOException | NamingException | JMSException e) {
logger.log(Level.SEVERE, null, e);
}
}

private static void initSSL() {
  // 
}
}

-
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org





--
Tim Bish
twitter: @tabish121
blog: http://timbish.blogspot.com/


-
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org



Re: AMQP 1.0 Qpid JMS and an Issue with Failover/Reconnect

2016-03-23 Thread Aleks Balaban

Tim,

Thx, good to know that the failover works! Obviously I've been doing 
something wrong. Well, as you requested here is my JMS/AMQP client 
source (I have removed the SSL initialization part used for amqps 
conncetion ):



Connection URI:
connectionfactory.nm = 
failover:(amqps://somedomain.com:5671)?failover.reconnectDelay=2000=1



Source code:

public class TestClient implements Runnable {

private static final Logger logger = 
Logger.getLogger(TestClient.class.getName());

private static Connection connection;

public static void main(String[] args) {

org.apache.log4j.PropertyConfigurator.configure("./log4j.properties");

initSSL();

new Thread(new TestClient()).start();

Runtime.getRuntime().addShutdownHook(new Thread(() -> {

logger.info("Shutting down...");

try {
if (connection != null) {
connection.close();
}
} catch (JMSException e) {
logger.warning(e.getMessage());
}
}));
}

@Override
public void run() {

try {
Properties properties = new Properties();

if (System.getProperty("nmclient.configuration") == null) {
File jarPath = new 
File(TestClient.class.getProtectionDomain().getCodeSource().getLocation().getPath());

String propertiesPath = jarPath.getParent();
properties.load(new FileInputStream(propertiesPath + 
"/config.properties"));

} else {
properties.load(new 
FileInputStream(System.getProperty("nmclient.configuration")));

}

Context context = new InitialContext(properties);
ConnectionFactory connectionFactory = (ConnectionFactory) 
context.lookup("nm");


connection = connectionFactory.createConnection();

connection.setExceptionListener((final JMSException e) -> {
logger.log(Level.SEVERE, null, e);
});

Session consumerSession = connection.createSession(false, 
Session.CLIENT_ACKNOWLEDGE);

Queue queueEaup = (Queue) context.lookup("eaup");
MessageConsumer messageConsumer = 
consumerSession.createConsumer(queueEaup);


messageConsumer.setMessageListener((final Message message) -> {
try {
if (message instanceof TextMessage) {

TextMessage payload = (TextMessage) message;
logger.info(payload.getText());
}
message.acknowledge();
} catch (Exception e) {
logger.log(Level.SEVERE, null, e);
}
});

connection.start();

} catch (IOException | NamingException | JMSException e) {
logger.log(Level.SEVERE, null, e);
}
}

private static void initSSL() {
  // 
}
}

-
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org



Re: AMQP 1.0 Qpid JMS and an Issue with Failover/Reconnect

2016-03-22 Thread Timothy Bish

On 03/22/2016 12:51 PM, Aleks Balaban wrote:
Thank you for writing back. My client quite minimalistic JMS client 
application with usual JMS stuff such as Connection, Session objects 
and "onMessage" listeners, which does nothing but connect to an AMQP 
server and waits to receive notifications/messages. It works just 
fine, only it isn't capable to re-establish the underlying SSL 
connection when something went wrong and that happens almost every 
day. I'm running it in a debug mode and the log I posted earlier is 
all I have. Obviously, the connection failure has been detected 
properly (for testing purposes I caused it by shooting down the 
internet connection) and the FailoverProvider makes two attempts to 
re-establish the connection. Both of them fails because the internet 
is off and suddenly some thread executor takes over and terminates 
everything. I'm just wondering is there any example in the web or 
anybody was trying to achieve the same. The documentation seems to be 
insufficient to find out what was wrong. What I've been thinking 
about, do I need to take care about configuration attributes at 
different communication levels? For example, do I have to take care 
manually that TCP, AMQP and JMS configuration parameters harmonize 
with each other?


-
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org


I wrote a small test using your provided failover options and my test 
sits for as long as I let it trying to reconnect.  I would take a look 
at your code and see where you might be closing the connection as there 
should be no issue with these options.


--
Tim Bish
twitter: @tabish121
blog: http://timbish.blogspot.com/


-
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org



Re: Re: AMQP 1.0 Qpid JMS and an Issue with Failover/Reconnect

2016-03-22 Thread Aleks Balaban
Thank you for writing back. My client quite minimalistic JMS client 
application with usual JMS stuff such as Connection, Session objects and 
"onMessage" listeners, which does nothing but connect to an AMQP server 
and waits to receive notifications/messages. It works just fine, only it 
isn't capable to re-establish the underlying SSL connection when 
something went wrong and that happens almost every day. I'm running it 
in a debug mode and the log I posted earlier is all I have. Obviously, 
the connection failure has been detected properly (for testing purposes 
I caused it by shooting down the internet connection) and the 
FailoverProvider makes two attempts to re-establish the connection. Both 
of them fails because the internet is off and suddenly some thread 
executor takes over and terminates everything. I'm just wondering is 
there any example in the web or anybody was trying to achieve the same. 
The documentation seems to be insufficient to find out what was wrong. 
What I've been thinking about, do I need to take care about 
configuration attributes at different communication levels? For example, 
do I have to take care manually that TCP, AMQP and JMS configuration 
parameters harmonize with each other?


-
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org



Re: AMQP 1.0 Qpid JMS and an Issue with Failover/Reconnect

2016-03-22 Thread Timothy Bish


I'd recommend that you post some code to show what your client is 
doing.  The logs really don't provide enough information to diagnose 
what might be going on.


On 03/22/2016 11:07 AM, Aleks Balaban wrote:

Hi,

Im using Qpid JMS 0.8.0 library in order to implement a standalone 
Java AMQP client. Because the underlying transport connection tends to 
break every couple of hours I was trying to configure the reconnection 
attempts (like failover but to the same server) using following 
configuration:


failover:(amqps://someurl:5671)?failover.reconnectDelay=2000=1 



In accordance with Qpid failover configuration explanation I expect my 
client to keep trying to reconnect increasing the attempt delays for 
factor 2 (starting with 2 seconds). Instead, according to the log 
file, only two attempts to reconnect have been performed when a 
connection failure was detected and at the end the whole client 
application has been terminated, what I definitively would like to 
avoid! Here is the log file:


2016-03-22 14:29:40 INFO AmqpProvider:1190 - IdleTimeoutCheck closed 
the transport due to the peer exceeding our requested idle-timeout. 
2016-03-22 14:29:40 DEBUG FailoverProvider:761 - Failover: the 
provider reports failure: Transport closed due to the peer exceeding 
our requested idle-timeout 2016-03-22 14:29:40 DEBUG 
FailoverProvider:519 - handling Provider failure: Transport closed due 
to the peer exceeding our requested idle-timeout 2016-03-22 14:29:40 
DEBUG FailoverProvider:653 - Connection attempt:[1] to: 
amqps://publish.preops.nm.eurocontrol.int:5671 in-progress 2016-03-22 
14:29:40 INFO FailoverProvider:659 - Connection attempt:[1] to: 
amqps://publish.preops.nm.eurocontrol.int:5671 failed 2016-03-22 
14:29:40 WARN FailoverProvider:686 - Failed to connect after: 1 
attempt(s) continuing to retry. 2016-03-22 14:29:42 DEBUG 
FailoverProvider:653 - Connection attempt:[2] to: 
amqps://publish.preops.nm.eurocontrol.int:5671 in-progress 2016-03-22 
14:29:42 INFO FailoverProvider:659 - Connection attempt:[2] to: 
amqps://publish.preops.nm.eurocontrol.int:5671 failed 2016-03-22 
14:29:42 WARN FailoverProvider:686 - Failed to connect after: 2 
attempt(s) continuing to retry. 2016-03-22 14:29:43 DEBUG 
ThreadPoolUtils:156 - Shutdown of ExecutorService: 
java.util.concurrent.ThreadPoolExecutor@778970af[Terminated, pool size 
= 0, active threads = 0, queued tasks = 0, completed tasks = 0] is 
shutdown: true and terminated: true took: 0.000 seconds. 2016-03-22 
14:29:45 DEBUG ThreadPoolUtils:192 - Waited 2.004 seconds for 
ExecutorService: 
java.util.concurrent.ScheduledThreadPoolExecutor@877a470[Shutting 
down, pool size = 1, active threads = 0, queued tasks = 1, completed 
tasks = 3] to terminate... 2016-03-22 14:29:46 DEBUG 
ThreadPoolUtils:156 - Shutdown of ExecutorService: 
java.util.concurrent.ScheduledThreadPoolExecutor@877a470[Terminated, 
pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 
4] is shutdown: true and terminated: true took: 2.889 seconds.


Any idea, what I’m doing wrong here? Basically, what I'm looking for 
to achieve is a client which is capable to detect transport connection 
failure and try to reconnect every 5-10 seconds.


Many thanks!





--
Tim Bish
twitter: @tabish121
blog: http://timbish.blogspot.com/


-
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org



AMQP 1.0 Qpid JMS and an Issue with Failover/Reconnect

2016-03-22 Thread Aleks Balaban

Hi,

Im using Qpid JMS 0.8.0 library in order to implement a standalone Java 
AMQP client. Because the underlying transport connection tends to break 
every couple of hours I was trying to configure the reconnection 
attempts (like failover but to the same server) using following 
configuration:


failover:(amqps://someurl:5671)?failover.reconnectDelay=2000=1

In accordance with Qpid failover configuration explanation I expect my 
client to keep trying to reconnect increasing the attempt delays for 
factor 2 (starting with 2 seconds). Instead, according to the log file, 
only two attempts to reconnect have been performed when a connection 
failure was detected and at the end the whole client application has 
been terminated, what I definitively would like to avoid! Here is the 
log file:


2016-03-22 14:29:40 INFO AmqpProvider:1190 - IdleTimeoutCheck closed the 
transport due to the peer exceeding our requested idle-timeout. 
2016-03-22 14:29:40 DEBUG FailoverProvider:761 - Failover: the provider 
reports failure: Transport closed due to the peer exceeding our 
requested idle-timeout 2016-03-22 14:29:40 DEBUG FailoverProvider:519 - 
handling Provider failure: Transport closed due to the peer exceeding 
our requested idle-timeout 2016-03-22 14:29:40 DEBUG 
FailoverProvider:653 - Connection attempt:[1] to: 
amqps://publish.preops.nm.eurocontrol.int:5671 in-progress 2016-03-22 
14:29:40 INFO FailoverProvider:659 - Connection attempt:[1] to: 
amqps://publish.preops.nm.eurocontrol.int:5671 failed 2016-03-22 
14:29:40 WARN FailoverProvider:686 - Failed to connect after: 1 
attempt(s) continuing to retry. 2016-03-22 14:29:42 DEBUG 
FailoverProvider:653 - Connection attempt:[2] to: 
amqps://publish.preops.nm.eurocontrol.int:5671 in-progress 2016-03-22 
14:29:42 INFO FailoverProvider:659 - Connection attempt:[2] to: 
amqps://publish.preops.nm.eurocontrol.int:5671 failed 2016-03-22 
14:29:42 WARN FailoverProvider:686 - Failed to connect after: 2 
attempt(s) continuing to retry. 2016-03-22 14:29:43 DEBUG 
ThreadPoolUtils:156 - Shutdown of ExecutorService: 
java.util.concurrent.ThreadPoolExecutor@778970af[Terminated, pool size = 
0, active threads = 0, queued tasks = 0, completed tasks = 0] is 
shutdown: true and terminated: true took: 0.000 seconds. 2016-03-22 
14:29:45 DEBUG ThreadPoolUtils:192 - Waited 2.004 seconds for 
ExecutorService: 
java.util.concurrent.ScheduledThreadPoolExecutor@877a470[Shutting down, 
pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 
3] to terminate... 2016-03-22 14:29:46 DEBUG ThreadPoolUtils:156 - 
Shutdown of ExecutorService: 
java.util.concurrent.ScheduledThreadPoolExecutor@877a470[Terminated, 
pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 
4] is shutdown: true and terminated: true took: 2.889 seconds.


Any idea, what I’m doing wrong here? Basically, what I'm looking for to 
achieve is a client which is capable to detect transport connection 
failure and try to reconnect every 5-10 seconds.


Many thanks!