use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class ClientProducerImpl method doSend.
private void doSend(SimpleString sendingAddress, final Message msgToSend, final SendAcknowledgementHandler handler) throws ActiveMQException {
if (sendingAddress == null) {
sendingAddress = this.address;
}
session.startCall();
try {
// In case we received message from another protocol, we first need to convert it to core as the ClientProducer only understands core
ICoreMessage msg = msgToSend.toCore();
ClientProducerCredits theCredits;
boolean isLarge;
// server's on which case we can't' convert the message into large at the servers
if (sessionContext.supportsLargeMessage() && (getBodyInputStream(msg) != null || msg.isLargeMessage() || msg.getBodyBuffer().writerIndex() > minLargeMessageSize)) {
isLarge = true;
} else {
isLarge = false;
}
if (!isLarge) {
session.setAddress(msg, sendingAddress);
} else {
msg.setAddress(sendingAddress);
}
// Anonymous
theCredits = session.getCredits(sendingAddress, true);
if (rateLimiter != null) {
// Rate flow control
rateLimiter.limit();
}
if (groupID != null) {
msg.putStringProperty(Message.HDR_GROUP_ID, groupID);
}
final boolean sendBlockingConfig = msg.isDurable() ? blockOnDurableSend : blockOnNonDurableSend;
// if Handler != null, we will send non blocking
final boolean sendBlocking = sendBlockingConfig && handler == null;
session.workDone();
if (isLarge) {
largeMessageSend(sendBlocking, msg, theCredits, handler);
} else {
sendRegularMessage(sendingAddress, msg, sendBlocking, theCredits, handler);
}
} finally {
session.endCall();
}
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class MessageImplTest method getSetAttributes.
@Test
public void getSetAttributes() {
for (int j = 0; j < 10; j++) {
byte[] bytes = new byte[1000];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = RandomUtil.randomByte();
}
final byte type = RandomUtil.randomByte();
final boolean durable = RandomUtil.randomBoolean();
final long expiration = RandomUtil.randomLong();
final long timestamp = RandomUtil.randomLong();
final byte priority = RandomUtil.randomByte();
ICoreMessage message1 = new ClientMessageImpl(type, durable, expiration, timestamp, priority, 100);
ICoreMessage message = message1;
Assert.assertEquals(type, message.getType());
Assert.assertEquals(durable, message.isDurable());
Assert.assertEquals(expiration, message.getExpiration());
Assert.assertEquals(timestamp, message.getTimestamp());
Assert.assertEquals(priority, message.getPriority());
final SimpleString destination = new SimpleString(RandomUtil.randomString());
final boolean durable2 = RandomUtil.randomBoolean();
final long expiration2 = RandomUtil.randomLong();
final long timestamp2 = RandomUtil.randomLong();
final byte priority2 = RandomUtil.randomByte();
message.setAddress(destination);
Assert.assertEquals(destination, message.getAddressSimpleString());
message.setDurable(durable2);
Assert.assertEquals(durable2, message.isDurable());
message.setExpiration(expiration2);
Assert.assertEquals(expiration2, message.getExpiration());
message.setTimestamp(timestamp2);
Assert.assertEquals(timestamp2, message.getTimestamp());
message.setPriority(priority2);
Assert.assertEquals(priority2, message.getPriority());
}
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class PagingManagerImplTest method testPagingManager.
@Test
public void testPagingManager() throws Exception {
HierarchicalRepository<AddressSettings> addressSettings = new HierarchicalObjectRepository<>();
addressSettings.setDefault(new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE));
final StorageManager storageManager = new NullStorageManager();
PagingStoreFactoryNIO storeFactory = new PagingStoreFactoryNIO(storageManager, getPageDirFile(), 100, null, getOrderedExecutor(), true, null);
PagingManagerImpl managerImpl = new PagingManagerImpl(storeFactory, addressSettings);
managerImpl.start();
PagingStore store = managerImpl.getPageStore(new SimpleString("simple-test"));
ICoreMessage msg = createMessage(1L, new SimpleString("simple-test"), createRandomBuffer(10));
final RoutingContextImpl ctx = new RoutingContextImpl(null);
Assert.assertFalse(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
store.startPaging();
Assert.assertTrue(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
Page page = store.depage();
page.open();
List<PagedMessage> msgs = page.read(new NullStorageManager());
page.close();
Assert.assertEquals(1, msgs.size());
ActiveMQTestBase.assertEqualsByteArrays(msg.getBodyBuffer().writerIndex(), msg.getBodyBuffer().toByteBuffer().array(), (msgs.get(0).getMessage()).toCore().getBodyBuffer().toByteBuffer().array());
Assert.assertTrue(store.isPaging());
Assert.assertNull(store.depage());
final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
Assert.assertFalse(store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock));
}
use of org.apache.activemq.artemis.api.core.ICoreMessage 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.api.core.ICoreMessage in project activemq-artemis by apache.
the class MessageTransformationTest method testHeaderButNoPropertiesEncodeDecode.
@Test
public void testHeaderButNoPropertiesEncodeDecode() throws Exception {
Message incomingMessage = Proton.message();
incomingMessage.setBody(new AmqpValue("String payload for AMQP message conversion performance testing."));
incomingMessage.setDurable(true);
ICoreMessage core = new AMQPMessage(incomingMessage).toCore();
Message outboudMessage = AMQPConverter.getInstance().fromCore(core).getProtonMessage();
}
Aggregations