Uploaded image for project: 'ActiveMQ Artemis'
  1. ActiveMQ Artemis
  2. ARTEMIS-1236

Diverts are not reloaded on server restart

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 2.1.0
    • None
    • Broker
    • None

    Description

      When diverts are created dynamically they are lost after server restart.

      import static org.testng.Assert.assertEquals;
      import static org.testng.Assert.assertNull;
      
      import java.io.File;
      import java.io.IOException;
      import java.nio.file.Files;
      import java.util.Arrays;
      import java.util.HashMap;
      import java.util.HashSet;
      import java.util.Map;
      
      import org.apache.activemq.artemis.api.core.TransportConfiguration;
      import org.apache.activemq.artemis.core.config.Configuration;
      import org.apache.activemq.artemis.core.config.DivertConfiguration;
      import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
      import org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory;
      import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
      import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
      import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy;
      import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
      import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
      import org.apache.activemq.artemis.jms.server.config.JMSConfiguration;
      import org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl;
      import org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl;
      import org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS;
      import org.springframework.jms.core.JmsTemplate;
      import org.testng.annotations.Test;
      
      public class RestartTest {
      
      	@Test
      	public void divertsReloaded() throws Exception {
      		File tempDirectory = Files.createTempDirectory("").toFile();
      		tempDirectory.deleteOnExit();
      		String path = tempDirectory.getAbsolutePath();
      		EmbeddedJMS jms = createServer(path);
      		
      		DivertConfiguration divert = new DivertConfiguration();
      		divert.setAddress("from");
      		divert.setForwardingAddress("to");
      		divert.setName("divert");
      		divert.setExclusive(true);
      		jms.getActiveMQServer().deployDivert(divert);
      		
      		JmsTemplate template = queueTemplate();
      		
      		template.convertAndSend("from", "test");
      		String received = (String) template.receiveAndConvert("to");
      		assertEquals(received, "test");
      		assertNull(template.receiveAndConvert("from"));
      		jms.stop();
      		Thread.sleep(1000);
      		
      		jms = createServer(path);
      		
      		template.convertAndSend("from", "test");
      		received = (String) template.receiveAndConvert("to");
      		assertEquals(received, "test");
      		received = (String) template.receiveAndConvert("from");
      		assertNull(received);
      	}
      
      	private EmbeddedJMS createServer(String path) throws IOException, Exception {
      		EmbeddedJMS jms = new EmbeddedJMS();
      		Configuration configuration = new ConfigurationImpl();
      		HashSet<TransportConfiguration> transports = new HashSet<TransportConfiguration>();
      		Map<String, Object> transportConfig = new HashMap<String, Object>();
      		transportConfig.put(TransportConstants.HOST_PROP_NAME, "127.0.0.1");
      		transportConfig.put(TransportConstants.PORT_PROP_NAME, 61616);
      		transports.add(new TransportConfiguration(NettyAcceptorFactory.class.getName(), transportConfig));
      		configuration.addConnectorConfiguration("self", new TransportConfiguration(NettyConnectorFactory.class.getName(), transportConfig));
      		configuration.setAcceptorConfigurations(transports);
      		
      		configuration.setPagingDirectory(path + "/data/paging");
      		configuration.setBindingsDirectory(path + "/data/bindings");
      		configuration.setJournalDirectory(path + "/data/journal");
      		configuration.setLargeMessagesDirectory(path + "/data/large-messages");
      		configuration.setPersistenceEnabled(true);
      		configuration.setSecurityEnabled(false);
      		AddressSettings defaultAddressSettings = new AddressSettings();
      		defaultAddressSettings
      			.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE)
      			.setMaxDeliveryAttempts(-1)
      			.setRedeliveryDelay(0)
      			.setRedistributionDelay(0)
      			.setAutoCreateAddresses(false)
      			.setAutoCreateQueues(false)
      			.setAutoDeleteAddresses(false)
      			.setAutoDeleteQueues(false)
      			.setMaxSizeBytes(10L * 1024 * 1024)
      			.setPageSizeBytes(5L * 1024 * 1024);
      		configuration.addAddressesSetting("#", new AddressSettings(defaultAddressSettings));
      		
      		JMSConfiguration jmsConfiguration = new JMSConfigurationImpl();
      		JMSQueueConfigurationImpl queue1 = new JMSQueueConfigurationImpl();
      		queue1.setName("from");
      		queue1.setDurable(true);
      		JMSQueueConfigurationImpl queue2 = new JMSQueueConfigurationImpl();
      		queue2.setName("to");
      		queue2.setDurable(true);
      		jmsConfiguration.setQueueConfigurations(Arrays.asList(queue1, queue2));
      		jms.setJmsConfiguration(jmsConfiguration);
      		jms.setConfiguration(configuration);
      		
      		jms.start();
      		return jms;
      	}
      	
      	private ActiveMQConnectionFactory jmsConnectionFactory() {
      		Map<String, Object> params = new HashMap<String, Object>();
      		params.put(TransportConstants.HOST_PROP_NAME, "127.0.0.1");
      		params.put(TransportConstants.PORT_PROP_NAME, 61616);
      		TransportConfiguration transportConfiguration = new TransportConfiguration(
      				NettyConnectorFactory.class.getName(), params);
      		ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(false, transportConfiguration);
      		connectionFactory.setBlockOnAcknowledge(false);
      		connectionFactory.setBlockOnDurableSend(false);
      		connectionFactory.setBlockOnNonDurableSend(false);
      		return connectionFactory;
      	}
      	
      	private JmsTemplate queueTemplate() {
      		JmsTemplate jmsTemplate = new JmsTemplate();
      		jmsTemplate.setConnectionFactory(jmsConnectionFactory());
      		jmsTemplate.setReceiveTimeout(1000);
      		return jmsTemplate;
      	}
      }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              1506231@gmail.com Dmitry
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: