activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From preben <preben.asmus...@gmail.com>
Subject delete messages from artemis broker
Date Wed, 25 Oct 2017 13:05:10 GMT
Im switching from Activemq to Artemis and have to migrate some unittests

I got a activemq baseclass like ->

 @Before
    public void startEmbeddedBroker() throws Exception {
        broker = new BrokerService();
        TransportConnector connector =
broker.addConnector("tcp://localhost:61616");
        broker.setPersistent(false);
        broker.setUseJmx(true);
        broker.deleteAllMessages();
        broker.start();
        broker.waitUntilStarted();
        ActiveMQConnectionFactory connFactory = new
ActiveMQConnectionFactory(connector.getConnectUri() +
"?jms.prefetchPolicy.all=1");
        connection = connFactory.createConnection();
        connection.start();
    }

    @After
    public void stopEmbeddedBroker() throws Exception {
        // wait a bit to let client connections get act's before shutdown
        Thread.sleep(2000);
        connection.stop();
        broker.stop();
    }

That work well for activemq. 
The artemis test baseclass is refactored to ->

@Before
    public void startEmbeddedBroker() throws Exception {
        FileUtils.deleteQuietly(new File("target/data"));
        broker = new EmbeddedJMS();
        brokerUri = "tcp://localhost:61616";
        configureBroker(this.broker);
        startBroker();
    }

    protected void configureBroker(EmbeddedJMS broker) throws Exception {
        Configuration configuration = new ConfigurationImpl()
            .setPersistenceEnabled(false)
            .setJournalDirectory("target/data/journal")
            .setSecurityEnabled(false)
            .addAcceptorConfiguration("connector", brokerUri +
"?protocols=CORE")
            .addConnectorConfiguration("connector", new
TransportConfiguration(NettyConnectorFactory.class.getName()));

        JMSConfiguration jmsConfig = new JMSConfigurationImpl();

        ConnectionFactoryConfiguration cfConfig = new
ConnectionFactoryConfigurationImpl()
            .setName("cf").setConnectorNames(Arrays.asList("connector"))
            .setBindings("cf");
        jmsConfig.getConnectionFactoryConfigurations().add(cfConfig);

       
broker.setConfiguration(configuration).setJmsConfiguration(jmsConfig);
    }

    private void startBroker() throws Exception {
        broker.start();
    }

    @After
    public void stopEmbeddedBroker() throws Exception {
        broker.stop();
        broker = null;
    }

The only thing missing is the ability to purge all queus and topics like the
one for activemq =  *broker.deleteAllMessages()*;

Without that it seems like the tests will see messages enqued in previous
test (if in same test class) ??

How can I purge all messages in Artemis.

/preben





--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html

Mime
View raw message