You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by preben <pr...@gmail.com> on 2017/10/25 13:05:10 UTC

delete messages from artemis broker

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

Re: delete messages from artemis broker

Posted by Clebert Suconic <cl...@gmail.com>.
You could also remove the files.. use a temporary folder that's used
for each test.

On Wed, Oct 25, 2017 at 2:03 PM, preben <pr...@gmail.com> wrote:
> Thanks Justin. Will try it out
>
>
>
> --
> Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html



-- 
Clebert Suconic

Re: delete messages from artemis broker

Posted by preben <pr...@gmail.com>.
Thanks Justin. Will try it out



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

Re: delete messages from artemis broker

Posted by Justin Bertram <jb...@apache.org>.
You should be able to use the code I pasted previously (or some
approximation thereof) to get the functionality you're looking for.  Have
you tried that out?


Justin

On Wed, Oct 25, 2017 at 10:59 AM, preben <pr...@gmail.com> wrote:

> Actually I start and stop the broker between each test, but when running a
> series of tests it seems that the newly started broker picks up messages
> produced in the previous test ?
> I would have presumed, that it would get a clean broker. To work around
> this
> I need the deleteAllMessages.
>
> I like the EmbeddedJMSResource, and might use that instead.
>
> How can i get hold of all list of queues and topics via the
> EmbeddedJMSResouce so I can call removeMessages ?
>
> And it would be nice with a deleteAllMessages, but I'm not sure I got
> bandwidth to do a PR in the near future.
>
> /Preben
>
>
>
>
> --
> Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-
> f2341805.html
>

Re: delete messages from artemis broker

Posted by preben <pr...@gmail.com>.
Actually I start and stop the broker between each test, but when running a
series of tests it seems that the newly started broker picks up messages
produced in the previous test ? 
I would have presumed, that it would get a clean broker. To work around this
I need the deleteAllMessages.

I like the EmbeddedJMSResource, and might use that instead.

How can i get hold of all list of queues and topics via the
EmbeddedJMSResouce so I can call removeMessages ? 

And it would be nice with a deleteAllMessages, but I'm not sure I got
bandwidth to do a PR in the near future.

/Preben




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

Re: delete messages from artemis broker

Posted by Clebert Suconic <cl...@gmail.com>.
You could do it per queue...

What we do in our own testsuite.. is to stop the server and start the
server on each test.. and use small journal files.. so it starts
really fast.

There's even artemis-junit, that you could embed in your tests.. and
that would do that work for you.


Look into our test... EmbeddedJMSREsourceQueueTest.. which is testing
the EmbeddedJMSResource.


If you really want to keep the same external server running (i.e you
are running integration tests against the real server), then  you
could call removeMessages on each Queue.



If ActiveMQ had a deleteAllMessages method and you really want it, we
could have a simple implementation there as well. Would you liked to
send a PR?

On Wed, Oct 25, 2017 at 9:05 AM, preben <pr...@gmail.com> wrote:
> 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



-- 
Clebert Suconic

Re: delete messages from artemis broker

Posted by Justin Bertram <jb...@apache.org>.
You could do something like this:

  for (String queueName :
broker.getJMSServerManager().getActiveMQServer().getActiveMQServerControl().getQueueNames())
{

 ((QueueControl)broker.getJMSServerManager().getActiveMQServer().getManagementService().getResource(ResourceNames.QUEUE
+ queueName)).removeMessages(null);
  }

I didn't compile this so there may be some errors, but I think you get the
idea.


Justin

On Wed, Oct 25, 2017 at 8:05 AM, preben <pr...@gmail.com> wrote:

> 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
>