use of org.apache.activemq.artemis.api.core.client.ClientMessage in project candlepin by candlepin.
the class EventSinkImpl method queueEvent.
/**
* Adds an event to the queue to be sent on successful completion of the request or job.
* sendEvents() must be called for these events to actually go out. This happens
* automatically after each successful REST API request, and KingpingJob. If either
* is not successful, rollback() must be called.
*
* Events are filtered, meaning that some of them might not even get into ActiveMQ.
* Details about the filtering are documented in EventFilter class
*
* ActiveMQ transaction actually manages the queue of events to be sent.
*/
@Override
public void queueEvent(Event event) {
if (eventFilter.shouldFilter(event)) {
log.debug("Filtering event {}", event);
return;
}
modeManager.throwRestEasyExceptionIfInSuspendMode();
log.debug("Queuing event: {}", event);
try {
ClientSession session = getClientSession();
ClientMessage message = session.createMessage(true);
String eventString = mapper.writeValueAsString(event);
message.getBodyBuffer().writeString(eventString);
// NOTE: not actually send until we commit the session.
getClientProducer().send(message);
} catch (Exception e) {
log.error("Error while trying to send event: {}", e);
}
}
use of org.apache.activemq.artemis.api.core.client.ClientMessage in project candlepin by candlepin.
the class EventSinkImplTest method sendEventShouldSendMessageOnProperEventInput.
@Test
public void sendEventShouldSendMessageOnProperEventInput() throws Exception {
final String content = "Simple String";
doReturn(content).when(mapper).writeValueAsString(anyObject());
ArgumentCaptor<ClientMessage> argumentCaptor = ArgumentCaptor.forClass(ClientMessage.class);
eventSinkImpl.queueEvent(mock(Event.class));
eventSinkImpl.sendEvents();
verify(mockClientProducer).send(argumentCaptor.capture());
assertEquals(content, argumentCaptor.getValue().getBodyBuffer().readString());
}
use of org.apache.activemq.artemis.api.core.client.ClientMessage in project activemq-artemis by apache.
the class RawAckTest method testAck.
@Test
public void testAck() throws Exception {
ClientMessage message;
message = session.createMessage(Message.OBJECT_TYPE, false);
message.getBodyBuffer().writeInt("hello".getBytes().length);
message.getBodyBuffer().writeBytes("hello".getBytes());
producer.send(message);
Thread.sleep(100);
ClientSession sessionConsumer = sessionFactory.createSession(true, true);
ClientConsumer consumer = sessionConsumer.createConsumer("testQueue");
sessionConsumer.start();
MyThread t = new MyThread(consumer);
t.start();
t.join();
Assert.assertTrue(passed);
passed = false;
message = session.createMessage(false);
message.getBodyBuffer().writeInt("hello2".getBytes().length);
message.getBodyBuffer().writeBytes("hello2".getBytes());
producer.send(message);
Thread.sleep(100);
t = new MyThread(consumer);
t.start();
t.join();
Assert.assertTrue(passed);
}
use of org.apache.activemq.artemis.api.core.client.ClientMessage in project activemq-artemis by apache.
the class TransformTest method publish.
public static void publish(String destination, Serializable object, String contentType) throws Exception {
ClientSession session = manager.getQueueManager().getSessionFactory().createSession();
try {
ClientProducer producer = session.createProducer(destination);
ClientMessage message = session.createMessage(Message.OBJECT_TYPE, false);
if (contentType == null) {
ActiveMQ.setEntity(message, object);
} else
ActiveMQ.setEntity(message, object, contentType);
producer.send(message);
session.start();
} finally {
session.close();
}
}
use of org.apache.activemq.artemis.api.core.client.ClientMessage in project activemq-artemis by apache.
the class MultipleEmbeddedActiveMQResourcesTest method testMultipleServers.
@Test
public void testMultipleServers() throws Exception {
ClientMessage sentOne = serverOne.sendMessage(TEST_ADDRESS_ONE, TEST_BODY);
assertNotNull(String.format(ASSERT_SENT_FORMAT, TEST_QUEUE_ONE), sentOne);
ClientMessage receivedOne = serverOne.receiveMessage(TEST_QUEUE_ONE);
assertNotNull(String.format(ASSERT_RECEIVED_FORMAT, TEST_QUEUE_TWO), receivedOne);
ClientMessage sentTwo = serverTwo.sendMessage(TEST_ADDRESS_TWO, TEST_BODY);
assertNotNull(String.format(ASSERT_SENT_FORMAT, TEST_QUEUE_TWO), sentOne);
ClientMessage receivedTwo = serverTwo.receiveMessage(TEST_QUEUE_TWO);
assertNotNull(String.format(ASSERT_RECEIVED_FORMAT, TEST_QUEUE_TWO), receivedOne);
}
Aggregations