forked from amazon-mq/upstreaming-activemq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mirrored queue does not mirror replication queues (amazon-mq#25)
- Loading branch information
1 parent
fa6d603
commit b3e3b19
Showing
5 changed files
with
319 additions
and
3 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...mq-broker/src/main/java/org/apache/activemq/replica/ReplicaMirroredDestinationFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* 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.replica; | ||
|
||
import org.apache.activemq.broker.ProducerBrokerExchange; | ||
import org.apache.activemq.broker.region.Destination; | ||
import org.apache.activemq.broker.region.DestinationFilter; | ||
import org.apache.activemq.command.Message; | ||
|
||
public class ReplicaMirroredDestinationFilter extends DestinationFilter { | ||
|
||
private final ReplicaRoleManagementBroker roleManagementBroker; | ||
|
||
public ReplicaMirroredDestinationFilter(Destination next, ReplicaRoleManagementBroker roleManagementBroker) { | ||
super(next); | ||
this.roleManagementBroker = roleManagementBroker; | ||
} | ||
|
||
@Override | ||
public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception { | ||
if (ReplicaSupport.isReplicationDestination(messageSend.getDestination()) || | ||
(roleManagementBroker.getRole() != ReplicaRole.source && getNext() instanceof DestinationFilter)) { | ||
((DestinationFilter) getNext()).getNext().send(producerExchange, messageSend); | ||
} else { | ||
super.send(producerExchange, messageSend); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...oker/src/main/java/org/apache/activemq/replica/ReplicaMirroredDestinationInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.replica; | ||
|
||
import org.apache.activemq.broker.Broker; | ||
import org.apache.activemq.broker.ConnectionContext; | ||
import org.apache.activemq.broker.region.Destination; | ||
import org.apache.activemq.broker.region.DestinationInterceptor; | ||
import org.apache.activemq.command.ActiveMQDestination; | ||
|
||
public class ReplicaMirroredDestinationInterceptor implements DestinationInterceptor { | ||
|
||
private final ReplicaRoleManagementBroker roleManagementBroker; | ||
|
||
public ReplicaMirroredDestinationInterceptor(ReplicaRoleManagementBroker roleManagementBroker) { | ||
this.roleManagementBroker = roleManagementBroker; | ||
} | ||
|
||
@Override | ||
public Destination intercept(Destination destination) { | ||
return new ReplicaMirroredDestinationFilter(destination, roleManagementBroker); | ||
} | ||
|
||
@Override | ||
public void remove(Destination destination) { | ||
} | ||
|
||
@Override | ||
public void create(Broker broker, ConnectionContext context, ActiveMQDestination destination) throws Exception { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
...-tests/src/test/java/org/apache/activemq/broker/replica/ReplicaPluginMirrorQueueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
/** | ||
* 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.broker.replica; | ||
|
||
import org.apache.activemq.ActiveMQConnectionFactory; | ||
import org.apache.activemq.command.ActiveMQTextMessage; | ||
|
||
import javax.jms.Connection; | ||
import javax.jms.Message; | ||
import javax.jms.MessageConsumer; | ||
import javax.jms.MessageProducer; | ||
import javax.jms.Session; | ||
import javax.jms.TextMessage; | ||
|
||
public class ReplicaPluginMirrorQueueTest extends ReplicaPluginTestSupport { | ||
|
||
protected Connection firstBrokerConnection; | ||
protected Connection secondBrokerConnection; | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
|
||
} | ||
@Override | ||
protected void tearDown() throws Exception { | ||
if (firstBrokerConnection != null) { | ||
firstBrokerConnection.close(); | ||
firstBrokerConnection = null; | ||
} | ||
if (secondBrokerConnection != null) { | ||
secondBrokerConnection.close(); | ||
secondBrokerConnection = null; | ||
} | ||
|
||
super.tearDown(); | ||
} | ||
|
||
public void testSendMessageWhenPrimaryIsMirrored() throws Exception { | ||
firstBroker = createFirstBroker(); | ||
firstBroker.setUseMirroredQueues(true); | ||
secondBroker = createSecondBroker(); | ||
startFirstBroker(); | ||
startSecondBroker(); | ||
|
||
firstBrokerConnectionFactory = new ActiveMQConnectionFactory(firstBindAddress); | ||
secondBrokerConnectionFactory = new ActiveMQConnectionFactory(secondBindAddress); | ||
destination = createDestination(); | ||
firstBrokerConnection = firstBrokerConnectionFactory.createConnection(); | ||
firstBrokerConnection.start(); | ||
secondBrokerConnection = secondBrokerConnectionFactory.createConnection(); | ||
secondBrokerConnection.start(); | ||
|
||
waitUntilReplicationQueueHasConsumer(firstBroker); | ||
|
||
Session firstBrokerSession = firstBrokerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); | ||
MessageProducer firstBrokerProducer = firstBrokerSession.createProducer(destination); | ||
MessageConsumer firstBrokerConsumer = firstBrokerSession.createConsumer(destination); | ||
|
||
Session secondBrokerSession = secondBrokerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); | ||
MessageConsumer secondBrokerConsumer = secondBrokerSession.createConsumer(destination); | ||
|
||
ActiveMQTextMessage message = new ActiveMQTextMessage(); | ||
message.setText(getName()); | ||
firstBrokerProducer.send(message); | ||
|
||
Message receivedMessage = secondBrokerConsumer.receive(LONG_TIMEOUT); | ||
assertNull(receivedMessage); | ||
|
||
receivedMessage = firstBrokerConsumer.receive(SHORT_TIMEOUT); | ||
assertNotNull(receivedMessage); | ||
assertTrue(receivedMessage instanceof TextMessage); | ||
assertEquals(getName(), ((TextMessage) receivedMessage).getText()); | ||
|
||
receivedMessage.acknowledge(); | ||
|
||
Thread.sleep(LONG_TIMEOUT); | ||
secondBrokerSession.close(); | ||
secondBrokerSession = secondBrokerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); | ||
secondBrokerConsumer = secondBrokerSession.createConsumer(destination); | ||
|
||
receivedMessage = secondBrokerConsumer.receive(SHORT_TIMEOUT); | ||
assertNull(receivedMessage); | ||
|
||
firstBrokerSession.close(); | ||
secondBrokerSession.close(); | ||
} | ||
|
||
public void testSendMessageWhenReplicaIsMirrored() throws Exception { | ||
firstBroker = createFirstBroker(); | ||
secondBroker = createSecondBroker(); | ||
secondBroker.setUseMirroredQueues(true); | ||
startFirstBroker(); | ||
startSecondBroker(); | ||
|
||
firstBrokerConnectionFactory = new ActiveMQConnectionFactory(firstBindAddress); | ||
secondBrokerConnectionFactory = new ActiveMQConnectionFactory(secondBindAddress); | ||
destination = createDestination(); | ||
firstBrokerConnection = firstBrokerConnectionFactory.createConnection(); | ||
firstBrokerConnection.start(); | ||
secondBrokerConnection = secondBrokerConnectionFactory.createConnection(); | ||
secondBrokerConnection.start(); | ||
|
||
waitUntilReplicationQueueHasConsumer(firstBroker); | ||
|
||
Session firstBrokerSession = firstBrokerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); | ||
MessageProducer firstBrokerProducer = firstBrokerSession.createProducer(destination); | ||
MessageConsumer firstBrokerConsumer = firstBrokerSession.createConsumer(destination); | ||
|
||
Session secondBrokerSession = secondBrokerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); | ||
MessageConsumer secondBrokerConsumer = secondBrokerSession.createConsumer(destination); | ||
|
||
ActiveMQTextMessage message = new ActiveMQTextMessage(); | ||
message.setText(getName()); | ||
firstBrokerProducer.send(message); | ||
|
||
Message receivedMessage = secondBrokerConsumer.receive(LONG_TIMEOUT); | ||
assertNotNull(receivedMessage); | ||
assertTrue(receivedMessage instanceof TextMessage); | ||
assertEquals(getName(), ((TextMessage) receivedMessage).getText()); | ||
|
||
receivedMessage = firstBrokerConsumer.receive(SHORT_TIMEOUT); | ||
assertNotNull(receivedMessage); | ||
assertTrue(receivedMessage instanceof TextMessage); | ||
assertEquals(getName(), ((TextMessage) receivedMessage).getText()); | ||
|
||
receivedMessage.acknowledge(); | ||
|
||
Thread.sleep(LONG_TIMEOUT); | ||
secondBrokerSession.close(); | ||
secondBrokerSession = secondBrokerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); | ||
secondBrokerConsumer = secondBrokerSession.createConsumer(destination); | ||
|
||
receivedMessage = secondBrokerConsumer.receive(SHORT_TIMEOUT); | ||
assertNull(receivedMessage); | ||
|
||
firstBrokerSession.close(); | ||
secondBrokerSession.close(); | ||
} | ||
|
||
public void testSendMessageWhenBothSidesMirrored() throws Exception { | ||
firstBroker = createFirstBroker(); | ||
firstBroker.setUseMirroredQueues(true); | ||
secondBroker = createSecondBroker(); | ||
secondBroker.setUseMirroredQueues(true); | ||
startFirstBroker(); | ||
startSecondBroker(); | ||
|
||
firstBrokerConnectionFactory = new ActiveMQConnectionFactory(firstBindAddress); | ||
secondBrokerConnectionFactory = new ActiveMQConnectionFactory(secondBindAddress); | ||
destination = createDestination(); | ||
firstBrokerConnection = firstBrokerConnectionFactory.createConnection(); | ||
firstBrokerConnection.start(); | ||
secondBrokerConnection = secondBrokerConnectionFactory.createConnection(); | ||
secondBrokerConnection.start(); | ||
|
||
waitUntilReplicationQueueHasConsumer(firstBroker); | ||
|
||
Session firstBrokerSession = firstBrokerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); | ||
MessageProducer firstBrokerProducer = firstBrokerSession.createProducer(destination); | ||
MessageConsumer firstBrokerConsumer = firstBrokerSession.createConsumer(destination); | ||
|
||
Session secondBrokerSession = secondBrokerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); | ||
MessageConsumer secondBrokerConsumer = secondBrokerSession.createConsumer(destination); | ||
|
||
ActiveMQTextMessage message = new ActiveMQTextMessage(); | ||
message.setText(getName()); | ||
firstBrokerProducer.send(message); | ||
|
||
Message receivedMessage = secondBrokerConsumer.receive(LONG_TIMEOUT); | ||
assertNull(receivedMessage); | ||
|
||
receivedMessage = firstBrokerConsumer.receive(SHORT_TIMEOUT); | ||
assertNotNull(receivedMessage); | ||
assertTrue(receivedMessage instanceof TextMessage); | ||
assertEquals(getName(), ((TextMessage) receivedMessage).getText()); | ||
|
||
receivedMessage.acknowledge(); | ||
|
||
Thread.sleep(LONG_TIMEOUT); | ||
secondBrokerSession.close(); | ||
secondBrokerSession = secondBrokerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); | ||
secondBrokerConsumer = secondBrokerSession.createConsumer(destination); | ||
|
||
receivedMessage = secondBrokerConsumer.receive(SHORT_TIMEOUT); | ||
assertNull(receivedMessage); | ||
|
||
firstBrokerSession.close(); | ||
secondBrokerSession.close(); | ||
} | ||
|
||
|
||
} |