use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.
the class StompV11Test method testHeartBeatToTTL.
@Test
public void testHeartBeatToTTL() throws Exception {
ClientStompFrame frame;
ClientStompFrame reply;
int port = 61614;
uri = createStompClientUri(scheme, hostname, port);
server.getActiveMQServer().getRemotingService().createAcceptor("test", "tcp://127.0.0.1:" + port + "?connectionTtl=1000&connectionTtlMin=5000&connectionTtlMax=10000").start();
StompClientConnection connection = StompClientConnectionFactory.createClientConnection(uri);
// no heart beat at all if heat-beat absent
frame = connection.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
reply = connection.sendFrame(frame);
assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
Thread.sleep(3000);
assertEquals(Stomp.Responses.ERROR, connection.receiveFrame(1000).getCommand());
assertEquals(0, connection.getFrameQueueSize());
try {
assertFalse(connection.isConnected());
} catch (Exception e) {
// ignore
} finally {
connection.closeTransport();
}
// no heart beat for (0,0)
connection = StompClientConnectionFactory.createClientConnection(uri);
frame = connection.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "0,0").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
reply = connection.sendFrame(frame);
IntegrationTestLogger.LOGGER.info("Reply: " + reply);
assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
assertEquals("0,500", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
Thread.sleep(3000);
assertEquals(Stomp.Responses.ERROR, connection.receiveFrame(1000).getCommand());
assertEquals(0, connection.getFrameQueueSize());
try {
assertFalse(connection.isConnected());
} catch (Exception e) {
// ignore
} finally {
connection.closeTransport();
}
// heart-beat (1,0), should receive a min client ping accepted by server
connection = StompClientConnectionFactory.createClientConnection(uri);
frame = connection.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "1,0").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
reply = connection.sendFrame(frame);
assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
assertEquals("0,2500", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
Thread.sleep(7000);
// send will fail
try {
assertFalse(connection.isConnected());
} catch (Exception e) {
// ignore
} finally {
connection.closeTransport();
}
// heart-beat (1,0), start a ping, then send a message, should be ok.
connection = StompClientConnectionFactory.createClientConnection(uri);
frame = connection.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "1,0").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
reply = connection.sendFrame(frame);
assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
assertEquals("0,2500", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
IntegrationTestLogger.LOGGER.info("========== start pinger!");
connection.startPinger(2500);
Thread.sleep(7000);
// now server side should be disconnected because we didn't send ping for 2 sec
// send will be ok
send(connection, getQueuePrefix() + getQueueName(), "text/plain", "Hello World");
connection.stopPinger();
connection.disconnect();
// heart-beat (20000,0), should receive a max client ping accepted by server
connection = StompClientConnectionFactory.createClientConnection(uri);
frame = connection.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "20000,0").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
reply = connection.sendFrame(frame);
assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
assertEquals("0,5000", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
Thread.sleep(12000);
// send will fail
try {
assertFalse(connection.isConnected());
} catch (Exception e) {
// ignore
} finally {
connection.closeTransport();
}
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.
the class StompV11Test method testSendAndReceiveWithHeartBeats.
@Test
public void testSendAndReceiveWithHeartBeats() throws Exception {
conn.connect(defUser, defPass);
for (int i = 0; i < 10; i++) {
send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World " + i + "!");
Thread.sleep(500);
}
// subscribe
StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
try {
ClientStompFrame frame = newConn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "500,1000").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
newConn.sendFrame(frame);
newConn.startPinger(500);
Thread.sleep(500);
subscribe(newConn, "a-sub");
int cnt = 0;
frame = newConn.receiveFrame();
while (frame != null) {
cnt++;
Thread.sleep(500);
frame = newConn.receiveFrame(5000);
}
assertEquals(10, cnt);
// unsub
unsubscribe(newConn, "a-sub");
} finally {
newConn.disconnect();
}
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.
the class StompV11Test method testSendWithHeartBeatsAndReceive.
@Test
public void testSendWithHeartBeatsAndReceive() throws Exception {
StompClientConnection newConn = null;
try {
ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "500,1000").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
conn.sendFrame(frame);
conn.startPinger(500);
for (int i = 0; i < 10; i++) {
send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World " + i + "!");
Thread.sleep(500);
}
// subscribe
newConn = StompClientConnectionFactory.createClientConnection(uri);
newConn.connect(defUser, defPass);
subscribe(newConn, "a-sub");
int cnt = 0;
frame = newConn.receiveFrame();
while (frame != null) {
cnt++;
Thread.sleep(500);
frame = newConn.receiveFrame(5000);
}
assertEquals(10, cnt);
// unsub
unsubscribe(newConn, "a-sub");
} finally {
if (newConn != null)
newConn.disconnect();
conn.disconnect();
}
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.
the class StompPropertiesInterceptorTest method testCheckInterceptedStompMessageProperties.
@Test(timeout = 60000)
public void testCheckInterceptedStompMessageProperties() throws Exception {
final String msgText = "Test intercepted message";
final String myHeader = "TestInterceptedHeader";
expectedProperties.put(MESSAGE_TEXT, msgText);
expectedProperties.put(MY_HEADER, myHeader);
StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
conn.connect(defUser, defPass);
ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
subFrame.addHeader("subscription-type", "ANYCAST");
subFrame.addHeader("destination", name.getMethodName());
subFrame.addHeader("ack", "auto");
subFrame.addHeader(MY_HEADER, myHeader);
subFrame.setBody(msgText);
conn.sendFrame(subFrame);
ClientStompFrame frame = conn.createFrame("SEND");
frame.addHeader("destination", name.getMethodName());
frame.addHeader("ack", "auto");
frame.addHeader(MY_HEADER, myHeader);
conn.sendFrame(frame);
conn.disconnect();
}
Aggregations