use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project microservice_framework by CJSCommonPlatform.
the class MessageProducerClient method startProducer.
/**
* Starts the message producer for a specific topic. Must be called
* before any messages can be sent.
*
* @param topicName the name of the topic to send to
*/
public void startProducer(final String topicName) {
try {
final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(QUEUE_URI);
connection = factory.createConnection();
connection.start();
session = connection.createSession(false, AUTO_ACKNOWLEDGE);
final Destination destination = session.createTopic(topicName);
messageProducer = session.createProducer(destination);
} catch (JMSException e) {
close();
throw new RuntimeException("Failed to create message producer to topic: '" + topicName + "', queue uri: '" + QUEUE_URI + "'", e);
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project microservice_framework by CJSCommonPlatform.
the class CakeShopIT method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
final DataSource eventStoreDataSource = initEventStoreDb();
EVENT_LOG_REPOSITORY = getEventJdbcRepository(eventStoreDataSource);
JMS_CONNECTION_FACTORY = new ActiveMQConnectionFactory(JMS_BROKER_URL);
final DataSource viewStoreDatasource = initViewStoreDb();
STREAM_STATUS_REPOSITORY = getSnapshotStreamStatusJdbcRepository(viewStoreDatasource);
SNAPSHOT_REPOSITORY = getSnapshotJdbcRepository(eventStoreDataSource);
initFileServiceDb();
Thread.sleep(300);
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class ArtemisCLIPlugin method doExecute.
@Override
protected void doExecute() throws MojoExecutionException, MojoFailureException {
// This is to avoid the Run issuing a kill at any point
Run.setEmbedded(true);
MavenProject project = (MavenProject) getPluginContext().get("project");
if (!isArtemisHome(home.toPath())) {
if (isArtemisHome(alternateHome.toPath())) {
home = alternateHome;
} else {
getLog().error("********************************************************************************************");
getLog().error("Could not locate suitable Artemis.home on either " + home + " or " + alternateHome);
getLog().error("Use the binary distribution or build the distribution before running the examples");
getLog().error("********************************************************************************************");
throw new MojoExecutionException("Couldn't find artemis.home");
}
}
try {
if (spawn) {
final Process process = org.apache.activemq.artemis.cli.process.ProcessBuilder.build(name, location, true, args);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
process.destroy();
}
});
if (testURI != null) {
long timeout = System.currentTimeMillis() + spawnTimeout;
while (System.currentTimeMillis() <= timeout) {
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(testURI)) {
if (testUser != null && testPassword != null) {
cf.createConnection(testUser, testPassword).close();
} else {
cf.createConnection().close();
}
getLog().info("Server started");
} catch (Exception e) {
getLog().info("awaiting server to start");
Thread.sleep(500);
continue;
}
break;
}
}
} else {
Artemis.execute(home, location, args);
}
Thread.sleep(600);
org.apache.activemq.artemis.cli.process.ProcessBuilder.cleanupProcess();
} catch (Throwable e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class EmbeddedJMSResourceMultipleFileConfigurationTest method setUp.
@Before
public void setUp() throws Exception {
connectionFactory = new ActiveMQConnectionFactory(jmsServer.getVmURL());
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
consumer = (ActiveMQMessageConsumer) session.createConsumer(ActiveMQDestination.createDestination(TEST_TOPIC, ActiveMQDestination.TYPE.TOPIC));
connection.start();
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class ArtemisTest method testQstat.
@Test
public void testQstat() throws Exception {
File instanceQstat = new File(temporaryFolder.getRoot(), "instanceQStat");
setupAuth(instanceQstat);
Run.setEmbedded(true);
Artemis.main("create", instanceQstat.getAbsolutePath(), "--silent", "--no-fsync", "--no-autotune", "--no-web", "--require-login");
System.setProperty("artemis.instance", instanceQstat.getAbsolutePath());
Artemis.internalExecute("run");
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection connection = cf.createConnection("admin", "admin")) {
// set up some queues with messages and consumers
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
sendMessages(session, "Test1", 15);
sendMessages(session, "Test11", 1);
sendMessages(session, "Test12", 1);
sendMessages(session, "Test20", 20);
MessageConsumer consumer = session.createConsumer(ActiveMQDestination.createDestination("queue://Test1", ActiveMQDestination.TYPE.QUEUE));
MessageConsumer consumer2 = session.createConsumer(ActiveMQDestination.createDestination("queue://Test1", ActiveMQDestination.TYPE.QUEUE));
for (int i = 0; i < 5; i++) {
Message message = consumer.receive(100);
}
// check all queues containing "Test1" are displayed
TestActionContext context = new TestActionContext();
StatQueue statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setQueueName("Test1");
statQueue.execute(context);
ArrayList<String> lines = getOutputLines(context, false);
// Header line + 3 queues
Assert.assertEquals("rows returned using queueName=Test1", 4, lines.size());
// check all queues are displayed when no Filter set
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 4 queues (at least - possibly other infra queues as well)
Assert.assertTrue("rows returned filtering no name ", 5 <= lines.size());
// check all queues containing "Test1" are displayed using Filter field NAME
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("NAME");
statQueue.setOperationName("CONTAINS");
statQueue.setValue("Test1");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 3 queues
Assert.assertEquals("rows returned filtering by NAME ", 4, lines.size());
// check only queue named "Test1" is displayed using Filter field NAME and operation EQUALS
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("NAME");
statQueue.setOperationName("EQUALS");
statQueue.setValue("Test1");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 1 queue only
Assert.assertEquals("rows returned filtering by NAME operation EQUALS", 2, lines.size());
// verify contents of queue stat line is correct
String queueTest1 = lines.get(1);
String[] parts = queueTest1.split("\\|");
Assert.assertEquals("queue name", "Test1", parts[1].trim());
Assert.assertEquals("address name", "Test1", parts[2].trim());
Assert.assertEquals("Consumer count", "2", parts[3].trim());
Assert.assertEquals("Message count", "10", parts[4].trim());
Assert.assertEquals("Added count", "15", parts[5].trim());
Assert.assertEquals("Delivering count", "10", parts[6].trim());
Assert.assertEquals("Acked count", "5", parts[7].trim());
// check all queues containing address "Test1" are displayed using Filter field ADDRESS
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("ADDRESS");
statQueue.setOperationName("CONTAINS");
statQueue.setValue("Test1");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 3 queues
Assert.assertEquals("rows returned filtering by ADDRESS", 4, lines.size());
// check all queues containing address "Test1" are displayed using Filter field MESSAGE_COUNT
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("MESSAGE_COUNT");
statQueue.setOperationName("CONTAINS");
statQueue.setValue("10");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 0 queues
Assert.assertEquals("rows returned filtering by MESSAGE_COUNT", 1, lines.size());
// check all queues containing address "Test1" are displayed using Filter field MESSAGE_ADDED
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("MESSAGES_ADDED");
statQueue.setOperationName("CONTAINS");
statQueue.setValue("20");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 0 queues
Assert.assertEquals("rows returned filtering by MESSAGES_ADDED", 1, lines.size());
// check queues with greater_than 19 MESSAGE_ADDED displayed
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("MESSAGES_ADDED");
statQueue.setOperationName("GREATER_THAN");
statQueue.setValue("19");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 1 queues
Assert.assertEquals("rows returned filtering by MESSAGES_ADDED", 2, lines.size());
String[] columns = lines.get(1).split("\\|");
Assert.assertEquals("queue name filtered by MESSAGES_ADDED GREATER_THAN ", "Test20", columns[2].trim());
// check queues with less_than 2 MESSAGE_ADDED displayed
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("MESSAGES_ADDED");
statQueue.setOperationName("LESS_THAN");
statQueue.setValue("2");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + "at least" 2 queues
Assert.assertTrue("rows returned filtering by MESSAGES_ADDED LESS_THAN", 2 <= lines.size());
// walk the result returned and the specific destinations are not part of the output
for (String line : lines) {
columns = line.split("\\|");
Assert.assertNotEquals("ensure Test20 is not part of returned result", "Test20", columns[2].trim());
Assert.assertNotEquals("ensure Test1 is not part of returned result", "Test1", columns[2].trim());
}
// check all queues containing address "Test1" are displayed using Filter field DELIVERING_COUNT
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("DELIVERING_COUNT");
statQueue.setOperationName("EQUALS");
statQueue.setValue("10");
statQueue.execute(context);
lines = getOutputLines(context, false);
columns = lines.get(1).split("\\|");
// Header line + 1 queues
Assert.assertEquals("rows returned filtering by DELIVERING_COUNT", 2, lines.size());
Assert.assertEquals("queue name filtered by DELIVERING_COUNT ", "Test1", columns[2].trim());
// check all queues containing address "Test1" are displayed using Filter field CONSUMER_COUNT
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("CONSUMER_COUNT");
statQueue.setOperationName("EQUALS");
statQueue.setValue("2");
statQueue.execute(context);
lines = getOutputLines(context, false);
columns = lines.get(1).split("\\|");
// Header line + 1 queues
Assert.assertEquals("rows returned filtering by CONSUMER_COUNT ", 2, lines.size());
Assert.assertEquals("queue name filtered by CONSUMER_COUNT ", "Test1", columns[2].trim());
// check all queues containing address "Test1" are displayed using Filter field MESSAGE_ACKED
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setFieldName("MESSAGES_ACKED");
statQueue.setOperationName("EQUALS");
statQueue.setValue("5");
statQueue.execute(context);
lines = getOutputLines(context, false);
columns = lines.get(1).split("\\|");
// Header line + 1 queues
Assert.assertEquals("rows returned filtering by MESSAGE_ACKED ", 2, lines.size());
Assert.assertEquals("queue name filtered by MESSAGE_ACKED", "Test1", columns[2].trim());
// check no queues are displayed when name does not match
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setQueueName("no_queue_name");
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 0 queues
Assert.assertEquals("rows returned by queueName for no Matching queue ", 1, lines.size());
// check maxrows is taking effect"
context = new TestActionContext();
statQueue = new StatQueue();
statQueue.setUser("admin");
statQueue.setPassword("admin");
statQueue.setQueueName("Test1");
statQueue.setMaxRows(1);
statQueue.execute(context);
lines = getOutputLines(context, false);
// Header line + 1 queue only
Assert.assertEquals("rows returned by maxRows=1", 2, lines.size());
} finally {
stopServer();
}
}
Aggregations