-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #6 Now using ActiveMQs own Redelivery Policy
- Loading branch information
Showing
4 changed files
with
126 additions
and
7 deletions.
There are no files selected for viewing
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
97 changes: 97 additions & 0 deletions
97
src/test/java/com/kjetland/dropwizard/activemq/ActiveMQReceiverHandlerReliveryTest.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,97 @@ | ||
package com.kjetland.dropwizard.activemq; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.activemq.ActiveMQConnectionFactory; | ||
import org.apache.activemq.broker.BrokerService; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class ActiveMQReceiverHandlerReliveryTest { | ||
|
||
final String url = "tcp://localhost:31219?" + | ||
"jms.redeliveryPolicy.maximumRedeliveries=3" + | ||
"&jms.redeliveryPolicy.initialRedeliveryDelay=100" + | ||
"&jms.redeliveryPolicy.redeliveryDelay=100"; | ||
|
||
BrokerService broker; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
broker = new BrokerService(); | ||
// configure the broker | ||
broker.addConnector(url); | ||
broker.start(); | ||
|
||
errorCount = 0; | ||
okCount = 0; | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
broker.stop(); | ||
// Just give the broker some time to stop | ||
Thread.sleep(1500); | ||
} | ||
|
||
int errorCount; | ||
int okCount; | ||
|
||
private void receiveMessage(String message) { | ||
|
||
if ( message.equals("fail")) { | ||
errorCount++; | ||
throw new RuntimeException("Error in receiveMessage"); | ||
} else { | ||
okCount++; | ||
System.out.println("receiveMessage: " + message); | ||
} | ||
} | ||
|
||
public boolean exceptionHandler(String message, Exception exception) { | ||
System.out.println("exceptionHandler: " + message + " - " + exception.getMessage()); | ||
return false; | ||
} | ||
|
||
@Test | ||
public void testRedeliveryQueue() throws Exception { | ||
doTestRedelivery("queue:someQueue"); | ||
} | ||
|
||
@Test | ||
public void testRedeliveryTopic() throws Exception { | ||
doTestRedelivery("topic:someTopic"); | ||
} | ||
|
||
private void doTestRedelivery(String destinationName) throws Exception { | ||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
ActiveMQReceiverHandler<String> h = new ActiveMQReceiverHandler<>( | ||
destinationName, | ||
connectionFactory, | ||
(m)->receiveMessage(m), | ||
String.class, | ||
objectMapper, | ||
(m,e) -> exceptionHandler(m,e), | ||
1); | ||
|
||
h.start(); | ||
|
||
ActiveMQSender sender = new ActiveMQSenderImpl(connectionFactory, objectMapper, destinationName, Optional.<Integer>empty(), false); | ||
|
||
sender.sendJson("fail"); | ||
sender.sendJson("ok1"); | ||
sender.sendJson("ok2"); | ||
|
||
Thread.sleep(1000); | ||
|
||
assertEquals(3+1, errorCount); | ||
assertEquals(2, okCount); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %X{akkaSource} %X{akkaPersistenceRecovering} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |