use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.
the class StompV12Test 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(v11Uri);
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.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);
}
Assert.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 StompTest method testPrefix.
public void testPrefix(final String prefix, final RoutingType routingType, final boolean send) throws Exception {
int port = 61614;
URI uri = createStompClientUri(scheme, hostname, port);
final String ADDRESS = UUID.randomUUID().toString();
final String PREFIXED_ADDRESS = prefix + ADDRESS;
String param = routingType.toString();
String urlParam = param.toLowerCase() + "Prefix";
server.getActiveMQServer().getRemotingService().createAcceptor("test", "tcp://" + hostname + ":" + port + "?protocols=" + StompProtocolManagerFactory.STOMP_PROTOCOL_NAME + "&" + urlParam + "=" + prefix).start();
StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
conn.connect(defUser, defPass);
// since this queue doesn't exist the broker should create a new address using the routing type matching the prefix
if (send) {
send(conn, PREFIXED_ADDRESS, null, "Hello World", true);
} else {
String uuid = UUID.randomUUID().toString();
ClientStompFrame frame = conn.createFrame(Stomp.Commands.SUBSCRIBE).addHeader(Stomp.Headers.Subscribe.DESTINATION, PREFIXED_ADDRESS).addHeader(Stomp.Headers.RECEIPT_REQUESTED, uuid);
frame = conn.sendFrame(frame);
assertEquals(uuid, frame.getHeader(Stomp.Headers.Response.RECEIPT_ID));
}
AddressInfo addressInfo = server.getActiveMQServer().getAddressInfo(SimpleString.toSimpleString(ADDRESS));
assertNotNull("No address was created with the name " + ADDRESS, addressInfo);
Set<RoutingType> routingTypes = new HashSet<>();
routingTypes.add(RoutingType.valueOf(param));
assertEquals(routingTypes, addressInfo.getRoutingTypes());
conn.disconnect();
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.
the class StompWebSocketMaxFrameTest method testStompSendReceiveWithMaxFramePayloadLength.
@Test
public void testStompSendReceiveWithMaxFramePayloadLength() throws Exception {
// Assert that sending message > default 64kb fails
int size = 65536;
String largeString1 = RandomStringUtils.randomAlphabetic(size);
String largeString2 = RandomStringUtils.randomAlphabetic(size);
StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri, false);
conn.getTransport().setMaxFrameSize(stompWSMaxFrameSize);
conn.getTransport().connect();
StompClientConnection conn2 = StompClientConnectionFactory.createClientConnection(wsURI, false);
conn2.getTransport().setMaxFrameSize(stompWSMaxFrameSize);
conn2.getTransport().connect();
Wait.waitFor(() -> conn2.getTransport().isConnected() && conn.getTransport().isConnected(), 10000);
conn.connect();
conn2.connect();
subscribeQueue(conn2, "sub1", getQueuePrefix() + getQueueName());
try {
// Client is kicked when sending frame > largest frame size.
send(conn, getQueuePrefix() + getQueueName(), "text/plain", largeString1, false);
Wait.waitFor(() -> !conn.getTransport().isConnected(), 2000);
assertFalse(conn.getTransport().isConnected());
send(conn2, getQueuePrefix() + getQueueName(), "text/plain", largeString2, false);
Wait.waitFor(() -> !conn2.getTransport().isConnected(), 2000);
assertTrue(conn2.getTransport().isConnected());
ClientStompFrame frame = conn2.receiveFrame();
assertNotNull(frame);
assertEquals(largeString2, frame.getBody());
} finally {
conn2.closeTransport();
conn.closeTransport();
}
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.
the class StompWithLargeMessagesTest method testSendReceiveLargePersistentMessages.
// stomp sender -> large -> stomp receiver
@Test
public void testSendReceiveLargePersistentMessages() throws Exception {
StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
conn.connect(defUser, defPass);
int count = 10;
int msgSize = 1024 * 1024;
char[] contents = new char[msgSize];
for (int i = 0; i < msgSize; i++) {
contents[i] = 'A';
}
String body = new String(contents);
for (int i = 0; i < count; i++) {
ClientStompFrame frame = conn.createFrame("SEND");
frame.addHeader("destination", getQueuePrefix() + getQueueName());
frame.addHeader("persistent", "true");
frame.setBody(body);
conn.sendFrame(frame);
}
ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
subFrame.addHeader("subscription-type", "ANYCAST");
subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
subFrame.addHeader("ack", "auto");
conn.sendFrame(subFrame);
for (int i = 0; i < count; i++) {
ClientStompFrame frame = conn.receiveFrame(60000);
Assert.assertNotNull(frame);
System.out.println("part of frame: " + frame.getBody().substring(0, 200));
Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
Assert.assertTrue(frame.getHeader("destination").equals(getQueuePrefix() + getQueueName()));
int index = frame.getBody().indexOf("AAAA");
assertEquals(msgSize, (frame.getBody().length() - index));
}
ClientStompFrame unsubFrame = conn.createFrame("UNSUBSCRIBE");
unsubFrame.addHeader("destination", getQueuePrefix() + getQueueName());
unsubFrame.addHeader("receipt", "567");
ClientStompFrame response = conn.sendFrame(unsubFrame);
assertNotNull(response);
assertNotNull(response.getCommand().equals("RECEIPT"));
conn.disconnect();
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection in project activemq-artemis by apache.
the class StompWithLargeMessagesTest method testReceiveLargePersistentMessagesFromCore.
// core sender -> large -> stomp receiver
@Test
public void testReceiveLargePersistentMessagesFromCore() throws Exception {
StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
conn.connect(defUser, defPass);
int msgSize = 3 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE;
char[] contents = new char[msgSize];
for (int i = 0; i < msgSize; i++) {
contents[i] = 'B';
}
String msg = new String(contents);
int count = 10;
for (int i = 0; i < count; i++) {
this.sendJmsMessage(msg);
}
ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
subFrame.addHeader("subscription-type", "ANYCAST");
subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
subFrame.addHeader("ack", "auto");
conn.sendFrame(subFrame);
for (int i = 0; i < count; i++) {
ClientStompFrame frame = conn.receiveFrame(60000);
Assert.assertNotNull(frame);
System.out.println("part of frame: " + frame.getBody().substring(0, 200));
Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
Assert.assertTrue(frame.getHeader("destination").equals(getQueuePrefix() + getQueueName()));
int index = frame.getBody().indexOf("BBB");
assertEquals(msgSize, (frame.getBody().length() - index));
}
ClientStompFrame unsubFrame = conn.createFrame("UNSUBSCRIBE");
unsubFrame.addHeader("destination", getQueuePrefix() + getQueueName());
unsubFrame.addHeader("receipt", "567");
ClientStompFrame response = conn.sendFrame(unsubFrame);
assertNotNull(response);
assertNotNull(response.getCommand().equals("RECEIPT"));
conn.disconnect();
}
Aggregations