use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class CoreMessageTest method sendThroughPacketsClient.
/**
* The message is received, then sent to the other side untouched
*/
@Test
public void sendThroughPacketsClient() {
CoreMessage decodedMessage = decodeMessage();
int encodeSize = decodedMessage.getEncodeSize();
Assert.assertEquals(BYTE_ENCODE.capacity(), encodeSize);
SessionReceiveMessage sendMessage = new SessionReceiveMessage(33, decodedMessage, 7);
sendMessage.setChannelID(777);
ActiveMQBuffer buffer = sendMessage.encode(null);
buffer.readerIndex(5);
SessionReceiveMessage sendMessageReceivedSent = new SessionReceiveMessage(new CoreMessage());
sendMessageReceivedSent.decode(buffer);
Assert.assertEquals(33, sendMessageReceivedSent.getConsumerID());
Assert.assertEquals(7, sendMessageReceivedSent.getDeliveryCount());
Assert.assertEquals(encodeSize, sendMessageReceivedSent.getMessage().getEncodeSize());
Assert.assertEquals(TEXT, TextMessageUtil.readBodyText(sendMessageReceivedSent.getMessage().getReadOnlyBodyBuffer()).toString());
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class CoreMessageTest method sendThroughPackets.
/**
* The message is received, then sent to the other side untouched
*/
@Test
public void sendThroughPackets() {
CoreMessage decodedMessage = decodeMessage();
int encodeSize = decodedMessage.getEncodeSize();
Assert.assertEquals(BYTE_ENCODE.capacity(), encodeSize);
SessionSendMessage sendMessage = new SessionSendMessage(decodedMessage, true, null);
sendMessage.setChannelID(777);
ActiveMQBuffer buffer = sendMessage.encode(null);
byte[] byteArray = buffer.byteBuf().array();
System.out.println("Sending " + ByteUtil.bytesToHex(buffer.toByteBuffer().array(), 1) + ", bytes = " + byteArray.length);
buffer.readerIndex(5);
SessionSendMessage sendMessageReceivedSent = new SessionSendMessage(new CoreMessage());
sendMessageReceivedSent.decode(buffer);
Assert.assertEquals(encodeSize, sendMessageReceivedSent.getMessage().getEncodeSize());
Assert.assertTrue(sendMessageReceivedSent.isRequiresResponse());
Assert.assertEquals(TEXT, TextMessageUtil.readBodyText(sendMessageReceivedSent.getMessage().getReadOnlyBodyBuffer()).toString());
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class MQTTUtil method createServerMessage.
private static ICoreMessage createServerMessage(MQTTSession session, SimpleString address, boolean retain, int qos) {
long id = session.getServer().getStorageManager().generateID();
CoreMessage message = new CoreMessage(id, DEFAULT_SERVER_MESSAGE_BUFFER_SIZE, session.getCoreMessageObjectPools());
message.setAddress(address);
message.putBooleanProperty(MQTT_MESSAGE_RETAIN_KEY, retain);
message.putIntProperty(MQTT_QOS_LEVEL_KEY, qos);
message.setType(Message.BYTES_TYPE);
return message;
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class VersionedStompFrameHandler method onSend.
public StompFrame onSend(StompFrame frame) {
StompFrame response = null;
try {
connection.validate();
String destination = getDestination(frame);
RoutingType routingType = getRoutingType(frame.getHeader(Headers.Send.DESTINATION_TYPE), frame.getHeader(Headers.Send.DESTINATION));
connection.autoCreateDestinationIfPossible(destination, routingType);
connection.checkDestination(destination);
connection.checkRoutingSemantics(destination, routingType);
String txID = frame.getHeader(Stomp.Headers.TRANSACTION);
long timestamp = System.currentTimeMillis();
CoreMessage message = connection.createServerMessage();
if (routingType != null) {
message.setRoutingType(routingType);
}
message.setTimestamp(timestamp);
message.setAddress(SimpleString.toSimpleString(destination));
StompUtils.copyStandardHeadersFromFrameToMessage(frame, message);
if (frame.hasHeader(Stomp.Headers.CONTENT_LENGTH)) {
message.setType(Message.BYTES_TYPE);
message.getBodyBuffer().writeBytes(frame.getBodyAsBytes());
} else {
message.setType(Message.TEXT_TYPE);
String text = frame.getBody();
message.getBodyBuffer().writeNullableSimpleString(SimpleString.toSimpleString(text));
}
connection.sendServerMessage(message, txID);
} catch (ActiveMQStompException e) {
response = e.getFrame();
} catch (Exception e) {
ActiveMQStompException error = BUNDLE.errorHandleSend(e).setHandler(this);
response = error.getFrame();
}
return response;
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class ReplicationTest method testSendPackets.
@Test
public void testSendPackets() throws Exception {
setupServer(true);
JournalStorageManager storage = getStorage();
manager = liveServer.getReplicationManager();
waitForComponent(manager);
Journal replicatedJournal = new ReplicatedJournal((byte) 1, new FakeJournal(), manager);
replicatedJournal.appendPrepareRecord(1, new FakeData(), false);
replicatedJournal.appendAddRecord(1, (byte) 1, new FakeData(), false);
replicatedJournal.appendUpdateRecord(1, (byte) 2, new FakeData(), false);
replicatedJournal.appendDeleteRecord(1, false);
replicatedJournal.appendAddRecordTransactional(2, 2, (byte) 1, new FakeData());
replicatedJournal.appendUpdateRecordTransactional(2, 2, (byte) 2, new FakeData());
replicatedJournal.appendCommitRecord(2, false);
replicatedJournal.appendDeleteRecordTransactional(3, 4, new FakeData());
replicatedJournal.appendPrepareRecord(3, new FakeData(), false);
replicatedJournal.appendRollbackRecord(3, false);
blockOnReplication(storage, manager);
Assert.assertTrue("Expecting no active tokens:" + manager.getActiveTokens(), manager.getActiveTokens().isEmpty());
CoreMessage msg = new CoreMessage().initBuffer(1024).setMessageID(1);
SimpleString dummy = new SimpleString("dummy");
msg.setAddress(dummy);
replicatedJournal.appendAddRecordTransactional(23, 24, (byte) 1, new FakeData());
PagedMessage pgmsg = new PagedMessageImpl(msg, new long[0]);
manager.pageWrite(pgmsg, 1);
manager.pageWrite(pgmsg, 2);
manager.pageWrite(pgmsg, 3);
manager.pageWrite(pgmsg, 4);
blockOnReplication(storage, manager);
PagingManager pagingManager = createPageManager(backupServer.getStorageManager(), backupServer.getConfiguration(), backupServer.getExecutorFactory(), backupServer.getAddressSettingsRepository());
PagingStore store = pagingManager.getPageStore(dummy);
store.start();
Assert.assertEquals(4, store.getNumberOfPages());
store.stop();
manager.pageDeleted(dummy, 1);
manager.pageDeleted(dummy, 2);
manager.pageDeleted(dummy, 3);
manager.pageDeleted(dummy, 4);
manager.pageDeleted(dummy, 5);
manager.pageDeleted(dummy, 6);
blockOnReplication(storage, manager);
CoreMessage serverMsg = new CoreMessage();
serverMsg.setMessageID(500);
serverMsg.setAddress(new SimpleString("tttt"));
ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(100);
serverMsg.encodeHeadersAndProperties(buffer.byteBuf());
manager.largeMessageBegin(500);
manager.largeMessageWrite(500, new byte[1024]);
manager.largeMessageDelete(Long.valueOf(500), storage);
blockOnReplication(storage, manager);
store.start();
Assert.assertEquals(0, store.getNumberOfPages());
}
Aggregations