Skip to content

Commit 860b29e

Browse files
committed
pushing up to repo
0 parents  commit 860b29e

14 files changed

+978
-0
lines changed

.gitignore

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/logs
2+
/target
3+
/.idea
4+
/.idea/*
5+
6+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
7+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
8+
9+
# User-specific stuff:
10+
.idea/**/workspace.xml
11+
.idea/**/tasks.xml
12+
.idea/dictionaries
13+
14+
# Sensitive or high-churn files:
15+
.idea/**/dataSources/
16+
.idea/**/dataSources.ids
17+
.idea/**/dataSources.xml
18+
.idea/**/dataSources.local.xml
19+
.idea/**/sqlDataSources.xml
20+
.idea/**/dynamic.xml
21+
.idea/**/uiDesigner.xml
22+
23+
# Gradle:
24+
.idea/**/gradle.xml
25+
.idea/**/libraries
26+
27+
# CMake
28+
cmake-build-debug/
29+
30+
# Mongo Explorer plugin:
31+
.idea/**/mongoSettings.xml
32+
33+
## File-based project format:
34+
*.iws
35+
*.iml
36+
37+
## Plugin-specific files:
38+
39+
# IntelliJ
40+
out/
41+
42+
# mpeltonen/sbt-idea plugin
43+
.idea_modules/
44+
45+
# JIRA plugin
46+
atlassian-ide-plugin.xml
47+
48+
# Cursive Clojure plugin
49+
.idea/replstate.xml
50+
51+
# Crashlytics plugin (for Android Studio and IntelliJ)
52+
com_crashlytics_export_strings.xml
53+
crashlytics.properties
54+
crashlytics-build.properties
55+
fabric.properties

pom.xml

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.redhat.refarch</groupId>
8+
<artifactId>amq7-refarch</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
13+
<maven.compiler.source>1.8</maven.compiler.source>
14+
<maven.compiler.target>1.8</maven.compiler.target>
15+
16+
<version.artemis-jms-client>2.0.0.amq-700011-redhat-1</version.artemis-jms-client>
17+
<version.activemq-all>5.15.0</version.activemq-all>
18+
<version.junit>4.12</version.junit>
19+
<version.jackson>2.9.1</version.jackson>
20+
<version.log4j-slf4j>2.9.1</version.log4j-slf4j>
21+
<version.qpid-jms-client>0.21.0.redhat-1</version.qpid-jms-client>
22+
<version.slf4j>1.7.25</version.slf4j>
23+
24+
</properties>
25+
26+
<dependencies>
27+
28+
<dependency>
29+
<groupId>org.apache.activemq</groupId>
30+
<artifactId>artemis-jms-client</artifactId>
31+
<version>${version.artemis-jms-client}</version>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.apache.qpid</groupId>
36+
<artifactId>qpid-jms-client</artifactId>
37+
<version>${version.qpid-jms-client}</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>junit</groupId>
42+
<artifactId>junit</artifactId>
43+
<version>${version.junit}</version>
44+
<scope>test</scope>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.slf4j</groupId>
49+
<artifactId>slf4j-log4j12</artifactId>
50+
<version>1.8.0-alpha2</version>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>com.fasterxml.jackson.dataformat</groupId>
55+
<artifactId>jackson-dataformat-yaml</artifactId>
56+
<version>${version.jackson}</version>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>com.fasterxml.jackson.core</groupId>
61+
<artifactId>jackson-databind</artifactId>
62+
<version>${version.jackson}</version>
63+
</dependency>
64+
65+
<dependency>
66+
<groupId>org.apache.httpcomponents</groupId>
67+
<artifactId>httpclient</artifactId>
68+
<version>4.5.3</version>
69+
</dependency>
70+
71+
<dependency>
72+
<groupId>com.google.guava</groupId>
73+
<artifactId>guava</artifactId>
74+
<version>23.0</version>
75+
<scope>test</scope>
76+
</dependency>
77+
78+
<dependency>
79+
<groupId>com.diffplug.durian</groupId>
80+
<artifactId>durian</artifactId>
81+
<version>3.4.0</version>
82+
<scope>test</scope>
83+
</dependency>
84+
85+
</dependencies>
86+
87+
<build>
88+
<testResources>
89+
<testResource>
90+
<directory>${project.basedir}/src/test/resources</directory>
91+
</testResource>
92+
</testResources>
93+
</build>
94+
95+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/*
2+
* Copyright 2005-2017 Red Hat, Inc.
3+
*
4+
* Red Hat licenses this file to you under the Apache License, version
5+
* 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13+
* implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
package com.redhat.refarch.amq7;
17+
18+
import org.apache.activemq.artemis.api.core.management.ResourceNames;
19+
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
20+
import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper;
21+
import org.junit.Assert;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
25+
import javax.jms.*;
26+
import javax.naming.InitialContext;
27+
import java.lang.IllegalStateException;
28+
import java.util.stream.IntStream;
29+
30+
import static com.redhat.refarch.amq7.Constants.*;
31+
32+
/***
33+
34+
*/
35+
public class BrokerDelegate {
36+
37+
private static final Logger logger = LoggerFactory.getLogger(BrokerDelegate.class);
38+
39+
private Session session;
40+
private Connection connection;
41+
42+
private MessageConsumer queueConsumer;
43+
private MessageConsumer topicConsumer;
44+
45+
private MessageProducer queueProducer;
46+
private MessageProducer topicProducer;
47+
48+
public BrokerDelegate(InitialContext initialContext, String brokerName, boolean autoAck, boolean consumeQueue, boolean consumeTopic,
49+
boolean produceToQueue, boolean produceToTopic) throws Exception {
50+
51+
ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup(brokerName + "/ConnectionFactory");
52+
connection = connectionFactory.createConnection(USERNAME.val(), PASSWORD.val());
53+
session = connection.createSession(false, autoAck ? Session.AUTO_ACKNOWLEDGE : Session.CLIENT_ACKNOWLEDGE);
54+
connection.start();
55+
56+
Queue queue = (Queue) initialContext.lookup("queue/" + QUEUE_NAME.val());
57+
Topic topic = (Topic) initialContext.lookup("topic/" + TOPIC_NAME.val());
58+
59+
if (consumeQueue)
60+
queueConsumer = session.createConsumer(queue);
61+
62+
if (consumeTopic)
63+
topicConsumer = session.createConsumer(topic);
64+
65+
if (produceToQueue)
66+
queueProducer = session.createProducer(queue);
67+
68+
if (produceToTopic)
69+
topicProducer = session.createProducer(topic);
70+
}
71+
72+
public void sendToQueue(Integer count) throws Exception {
73+
74+
if (queueProducer == null)
75+
throw new IllegalStateException("cannot publish to queue with null publisher");
76+
77+
IntStream.rangeClosed(1, count).forEach(i -> {
78+
try {
79+
queueProducer.send(session.createTextMessage("test"));
80+
81+
} catch (Exception e) {
82+
logger.error("error sending messages to queue", e);
83+
Assert.fail();
84+
}
85+
});
86+
}
87+
88+
public void sendToTopic(Integer count) throws Exception {
89+
90+
if (topicProducer == null)
91+
throw new IllegalStateException("cannot publish to topic with null publisher");
92+
93+
IntStream.rangeClosed(1, count).forEach(i -> {
94+
try {
95+
topicProducer.send(session.createTextMessage("test"));
96+
97+
} catch (Exception e) {
98+
logger.error("error sending messages", e);
99+
Assert.fail();
100+
}
101+
});
102+
}
103+
104+
public void receiveFromQueue(Integer count) throws Exception {
105+
106+
if (queueConsumer == null)
107+
throw new IllegalStateException("cannot receive from queue with null consumer");
108+
109+
IntStream.rangeClosed(1, count).forEach(i -> {
110+
try {
111+
Assert.assertNotNull("received message is null", queueConsumer.receive(Long.valueOf(TIMEOUT.val())));
112+
} catch (Exception e) {
113+
logger.error("error sending messages", e);
114+
Assert.fail();
115+
}
116+
});
117+
}
118+
119+
public void receiveFromQueue() throws Exception {
120+
receiveFromQueue(1);
121+
}
122+
123+
public void ackFromQueue(Integer count) throws Exception {
124+
125+
if (queueConsumer == null)
126+
throw new IllegalStateException("cannot receive from queue with null consumer");
127+
128+
IntStream.rangeClosed(1, count).forEach(i -> {
129+
try {
130+
Message message = queueConsumer.receive(Long.valueOf(TIMEOUT.val()));
131+
Assert.assertNotNull("received message is null", message);
132+
message.acknowledge();
133+
134+
} catch (Exception e) {
135+
logger.error("error sending messages", e);
136+
Assert.fail();
137+
}
138+
});
139+
}
140+
141+
public void ackFromQueue() throws Exception {
142+
ackFromQueue(1);
143+
}
144+
145+
public void receiveFromTopic(Integer count) throws Exception {
146+
147+
if (topicConsumer == null)
148+
throw new IllegalStateException("cannot receive from topic with null consumer");
149+
150+
IntStream.rangeClosed(1, count).forEach(i -> {
151+
try {
152+
Assert.assertNotNull("rcvd message is null", topicConsumer.receive(Long.valueOf(TIMEOUT.val())));
153+
} catch (Exception e) {
154+
logger.error("error sending messages", e);
155+
Assert.fail();
156+
}
157+
});
158+
}
159+
160+
public void sendShutdown() throws Exception {
161+
162+
QueueSession queueSession = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
163+
QueueRequestor requestor = new QueueRequestor(queueSession, ActiveMQJMSClient.createQueue("activemq.management"));
164+
165+
Message message = queueSession.createMessage();
166+
JMSManagementHelper.putOperationInvocation(message, ResourceNames.BROKER, "forceFailover");
167+
try {
168+
requestor.request(message);
169+
} catch (JMSException e) {
170+
if (!e.getLocalizedMessage().startsWith("AMQ119016")) {
171+
// we killed the broker - a connection failure is expected, throw anything else
172+
throw e;
173+
}
174+
}
175+
}
176+
177+
public MessageConsumer queueConsumer() {
178+
return queueConsumer;
179+
}
180+
}

0 commit comments

Comments
 (0)