Search in sources :

Example 1 with ClientMessage

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);
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 2 with ClientMessage

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());
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Test(org.junit.Test)

Example 3 with ClientMessage

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);
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Example 4 with ClientMessage

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();
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 5 with ClientMessage

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);
}
Also used : ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Test(org.junit.Test)

Aggregations

ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)889 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)708 Test (org.junit.Test)647 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)623 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)606 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)445 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)363 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)167 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)140 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)102 CountDownLatch (java.util.concurrent.CountDownLatch)99 Configuration (org.apache.activemq.artemis.core.config.Configuration)87 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)85 Queue (org.apache.activemq.artemis.core.server.Queue)72 Xid (javax.transaction.xa.Xid)67 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)63 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)54 HashMap (java.util.HashMap)53 ArrayList (java.util.ArrayList)51 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)47