use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class OpenTypeSupport method convert.
public static CompositeData convert(MessageReference ref) throws OpenDataException {
CompositeType ct;
ICoreMessage message = ref.getMessage().toCore();
Map<String, Object> fields;
byte type = message.getType();
switch(type) {
case Message.TEXT_TYPE:
ct = TEXT_FACTORY.getCompositeType();
fields = TEXT_FACTORY.getFields(ref);
break;
default:
ct = BYTES_FACTORY.getCompositeType();
fields = BYTES_FACTORY.getFields(ref);
break;
}
return new CompositeDataSupport(ct, fields);
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class Page method delete.
public boolean delete(final PagedMessage[] messages) throws Exception {
if (storageManager != null) {
storageManager.pageDeleted(storeName, pageId);
}
if (logger.isDebugEnabled()) {
logger.debug("Deleting pageNr=" + pageId + " on store " + storeName);
}
if (messages != null) {
for (PagedMessage msg : messages) {
if (msg.getMessage() instanceof ICoreMessage && (msg.getMessage()).isLargeMessage()) {
LargeServerMessage lmsg = (LargeServerMessage) msg.getMessage();
// Remember, cannot call delete directly here
// Because the large-message may be linked to another message
// or it may still being delivered even though it has been acked already
lmsg.decrementDelayDeletionCount();
}
}
}
try {
if (suspiciousRecords) {
ActiveMQServerLogger.LOGGER.pageInvalid(file.getFileName(), file.getFileName());
file.renameTo(file.getFileName() + ".invalidPage");
} else {
file.delete();
}
return true;
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.pageDeleteError(e);
return false;
}
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class MQTTUtil method createServerMessageFromByteBuf.
public static Message createServerMessageFromByteBuf(MQTTSession session, String topic, boolean retain, int qos, ByteBuf payload) {
String coreAddress = convertMQTTAddressFilterToCore(topic, session.getWildcardConfiguration());
SimpleString address = SimpleString.toSimpleString(coreAddress, session.getCoreMessageObjectPools().getAddressStringSimpleStringPool());
ICoreMessage message = createServerMessage(session, address, retain, qos);
message.getBodyBuffer().writeBytes(payload, 0, payload.readableBytes());
return message;
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class AMQPMessageTest method testExtraProperty.
@Test
public void testExtraProperty() {
MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
byte[] original = RandomUtil.randomBytes();
SimpleString name = SimpleString.toSimpleString("myProperty");
AMQPMessage decoded = encodeAndDecodeMessage(protonMessage);
decoded.setAddress("someAddress");
decoded.setMessageID(33);
decoded.putExtraBytesProperty(name, original);
ICoreMessage coreMessage = decoded.toCore();
Assert.assertEquals(original, coreMessage.getBytesProperty(name));
ActiveMQBuffer buffer = ActiveMQBuffers.pooledBuffer(10 * 1024);
try {
decoded.getPersister().encode(buffer, decoded);
// the journal reader will read 1 byte to find the persister
Assert.assertEquals(AMQPMessagePersisterV2.getInstance().getID(), buffer.readByte());
AMQPMessage readMessage = (AMQPMessage) decoded.getPersister().decode(buffer, null);
Assert.assertEquals(33, readMessage.getMessageID());
Assert.assertEquals("someAddress", readMessage.getAddress());
Assert.assertArrayEquals(original, readMessage.getExtraBytesProperty(name));
} finally {
buffer.release();
}
{
ICoreMessage embeddedMessage = EmbedMessageUtil.embedAsCoreMessage(decoded);
AMQPMessage readMessage = (AMQPMessage) EmbedMessageUtil.extractEmbedded(embeddedMessage);
Assert.assertEquals(33, readMessage.getMessageID());
Assert.assertEquals("someAddress", readMessage.getAddress());
Assert.assertArrayEquals(original, readMessage.getExtraBytesProperty(name));
}
}
use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.
the class TestConversions method testSimpleConversionText.
@Test
public void testSimpleConversionText() throws Exception {
Map<String, Object> mapprop = createPropertiesMap();
ApplicationProperties properties = new ApplicationProperties(mapprop);
MessageImpl message = (MessageImpl) Message.Factory.create();
message.setApplicationProperties(properties);
String text = "someText";
message.setBody(new AmqpValue(text));
AMQPMessage encodedMessage = new AMQPMessage(message);
ICoreMessage serverMessage = encodedMessage.toCore();
ServerJMSTextMessage textMessage = (ServerJMSTextMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);
textMessage.decode();
verifyProperties(textMessage);
Assert.assertEquals(text, textMessage.getText());
}
Aggregations