Search in sources :

Example 6 with SessionSendMessage

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage in project activemq-artemis by apache.

the class BridgeTest method internalTestMessageLoss.

/**
 * This test will ignore messages
 * What will cause the bridge to fail with a timeout
 * The bridge should still recover the failure and reconnect on that case
 */
public void internalTestMessageLoss(final boolean largeMessage) throws Exception {
    class MyInterceptor implements Interceptor {

        public boolean ignoreSends = true;

        public CountDownLatch latch;

        MyInterceptor(int numberOfIgnores) {
            latch = new CountDownLatch(numberOfIgnores);
        }

        @Override
        public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
            if (ignoreSends && packet instanceof SessionSendMessage || ignoreSends && packet instanceof SessionSendLargeMessage || ignoreSends && packet instanceof SessionSendContinuationMessage && !((SessionSendContinuationMessage) packet).isContinues()) {
                IntegrationTestLogger.LOGGER.info("IGNORED: " + packet);
                latch.countDown();
                return false;
            } else {
                IntegrationTestLogger.LOGGER.info(packet);
                return true;
            }
        }
    }
    MyInterceptor myInterceptor = new MyInterceptor(3);
    Map<String, Object> server0Params = new HashMap<>();
    server0 = createClusteredServerWithParams(isNetty(), 0, true, server0Params);
    Map<String, Object> server1Params = new HashMap<>();
    addTargetParameters(server1Params);
    server1 = createClusteredServerWithParams(isNetty(), 1, true, server1Params);
    final String testAddress = "testAddress";
    final String queueName0 = "queue0";
    final String forwardAddress = "forwardAddress";
    final String queueName1 = "queue1";
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
    TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
    HashMap<String, TransportConfiguration> connectors = new HashMap<>();
    connectors.put(server1tc.getName(), server1tc);
    server0.getConfiguration().setConnectorConfigurations(connectors);
    final int messageSize = 1024;
    final int numMessages = 1;
    ArrayList<String> connectorConfig = new ArrayList<>();
    connectorConfig.add(server1tc.getName());
    BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setRetryInterval(100).setReconnectAttempts(-1).setReconnectAttemptsOnSameNode(-1).setUseDuplicateDetection(false).setConfirmationWindowSize(numMessages * messageSize / 2).setStaticConnectors(connectorConfig).setCallTimeout(500);
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName1);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    server1.start();
    server1.getRemotingService().addIncomingInterceptor(myInterceptor);
    server0.start();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
    ClientSessionFactory sf0 = addSessionFactory(locator.createSessionFactory(server0tc));
    ClientSessionFactory sf1 = addSessionFactory(locator.createSessionFactory(server1tc));
    ClientSession session0 = sf0.createSession(false, true, true);
    ClientSession session1 = sf1.createSession(false, true, true);
    ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session1.createConsumer(queueName1);
    session1.start();
    final byte[] bytes = new byte[messageSize];
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        if (largeMessage) {
            message.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(10 * 1024));
        }
        message.putIntProperty(propKey, i);
        message.getBodyBuffer().writeBytes(bytes);
        producer0.send(message);
    }
    assertTrue("where is the countDown?", myInterceptor.latch.await(30, TimeUnit.SECONDS));
    myInterceptor.ignoreSends = false;
    server1.getRemotingService().removeIncomingInterceptor(myInterceptor);
    IntegrationTestLogger.LOGGER.info("No longer ignoring packets.");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(30000);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        if (largeMessage) {
            readLargeMessages(message, 10);
        }
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    session0.close();
    session1.close();
    sf0.close();
    sf1.close();
    closeFields();
    assertEquals("there should be no queues", 0, loadQueues(server0).size());
}
Also used : SessionSendContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendContinuationMessage) HashMap(java.util.HashMap) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ArrayList(java.util.ArrayList) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) Interceptor(org.apache.activemq.artemis.api.core.Interceptor) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) SessionSendLargeMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendLargeMessage) Packet(org.apache.activemq.artemis.core.protocol.core.Packet) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) SessionSendMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer)

Example 7 with SessionSendMessage

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage in project activemq-artemis by apache.

the class SimpleInterceptor method intercept.

@Override
public boolean intercept(final Packet packet, final RemotingConnection connection) throws ActiveMQException {
    System.out.println("SimpleInterceptor gets called!");
    System.out.println("Packet: " + packet.getClass().getName());
    System.out.println("RemotingConnection: " + connection.getRemoteAddress());
    if (packet instanceof SessionSendMessage) {
        SessionSendMessage realPacket = (SessionSendMessage) packet;
        Message msg = realPacket.getMessage();
        msg.putStringProperty(new SimpleString("newproperty"), new SimpleString("Hello from interceptor!"));
    }
    // the target
    return true;
}
Also used : SessionSendMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SessionSendMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage)

Example 8 with SessionSendMessage

use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage in project activemq-artemis by apache.

the class Outgoing method intercept.

@Override
public boolean intercept(final Packet packet, final RemotingConnection connection) throws ActiveMQException {
    System.out.println("Outgoin:Packet : " + packet);
    if (packet.getType() == PacketImpl.SESS_SEND) {
        SessionSendMessage p = (SessionSendMessage) packet;
        p.getMessage().putStringProperty("Outgoing", "sending");
    }
    return true;
}
Also used : SessionSendMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage)

Aggregations

SessionSendMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)3 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)2 Message (org.apache.activemq.artemis.api.core.Message)2 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQIOErrorException (org.apache.activemq.artemis.api.core.ActiveMQIOErrorException)1 ActiveMQQueueMaxConsumerLimitReached (org.apache.activemq.artemis.api.core.ActiveMQQueueMaxConsumerLimitReached)1 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)1 Interceptor (org.apache.activemq.artemis.api.core.Interceptor)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1