Skip to content

Commit

Permalink
ARTEMIS-218 auto-create in cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram committed Jan 5, 2016
1 parent 74de4ec commit e899c85
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,11 @@ private ActiveMQMessageConsumer createConsumer(final ActiveMQDestination dest,
if (dest.isQueue()) {
AddressQuery response = session.addressQuery(dest.getSimpleAddress());

if (!response.isExists()) {
/* The address query will send back exists=true even if the node only has a REMOTE binding for the destination.
* Therefore, we must check if the queue names list contains the exact name of the address to know whether or
* not a LOCAL binding for the address exists. If no LOCAL binding exists then it should be created here.
*/
if (!response.isExists() || !response.getQueueNames().contains(dest.getSimpleAddress())) {
if (response.isAutoCreateJmsQueues()) {
session.createQueue(dest.getSimpleAddress(), dest.getSimpleAddress(), true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.tests.integration.jms.cluster;

import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
import org.apache.activemq.artemis.tests.util.JMSClusteredTestBase;
import org.junit.Before;
import org.junit.Test;

public class AutoCreateQueueClusterTest extends JMSClusteredTestBase {

@Override
@Before
public void setUp() throws Exception {
//todo fix if needed
super.setUp();
jmsServer1.getActiveMQServer().setIdentity("Server 1");
jmsServer2.getActiveMQServer().setIdentity("Server 2");
}

@Override
protected boolean enablePersistence() {
return true;
}

@Test
public void testAutoCreate() throws Exception {
server1.getAddressSettingsRepository().getMatch("#").setAutoCreateJmsQueues(true).setRedistributionDelay(0);
server2.getAddressSettingsRepository().getMatch("#").setAutoCreateJmsQueues(true).setRedistributionDelay(0);
Connection conn1 = cf1.createConnection();
Connection conn2 = cf2.createConnection();
conn1.start();
conn2.start();

try {
Session session1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);

Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);

MessageProducer prod1 = session1.createProducer(ActiveMQJMSClient.createQueue("myQueue"));

prod1.setDeliveryMode(DeliveryMode.PERSISTENT);

prod1.send(session1.createTextMessage("m1"));

MessageConsumer cons2 = session2.createConsumer(ActiveMQJMSClient.createQueue("myQueue"));

TextMessage received = (TextMessage) cons2.receive(5000);

assertNotNull(received);

assertEquals("m1", received.getText());

cons2.close();
}
finally {
conn1.close();
conn2.close();
}
}
}

0 comments on commit e899c85

Please sign in to comment.