use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class NIOMultiThreadCompactorStressTest method addBogusData.
/**
* @throws ActiveMQException
*/
private void addBogusData(final int nmessages, final String queue) throws ActiveMQException {
ClientSession session = sf.createSession(false, false);
try {
session.createQueue(queue, queue, true);
} catch (Exception ignored) {
}
ClientProducer prod = session.createProducer(queue);
for (int i = 0; i < nmessages; i++) {
ClientMessage msg = session.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[1024]);
prod.send(msg);
}
session.commit();
session.start();
ClientConsumer cons = session.createConsumer(queue);
Assert.assertNotNull(cons.receive(1000));
session.rollback();
session.close();
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ClusterConnectionBridge method setupNotificationConsumer.
private void setupNotificationConsumer() throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("Setting up notificationConsumer between " + this.clusterConnection.getConnector() + " and " + flowRecord.getBridge().getForwardingConnection() + " clusterConnection = " + this.clusterConnection.getName() + " on server " + clusterConnection.getServer());
}
if (flowRecord != null) {
flowRecord.reset();
if (notifConsumer != null) {
try {
logger.debug("Closing notification Consumer for reopening " + notifConsumer + " on bridge " + this.getName());
notifConsumer.close();
notifConsumer = null;
} catch (ActiveMQException e) {
ActiveMQServerLogger.LOGGER.errorClosingConsumer(e);
}
}
// Get the queue data
String qName = "notif." + UUIDGenerator.getInstance().generateStringUUID() + "." + clusterConnection.getServer().toString().replaceAll(CompositeAddress.SEPARATOR, "_");
SimpleString notifQueueName = new SimpleString(qName);
SimpleString filter = new SimpleString(ManagementHelper.HDR_BINDING_TYPE + "<>" + BindingType.DIVERT.toInt() + " AND " + ManagementHelper.HDR_NOTIFICATION_TYPE + " IN ('" + CoreNotificationType.BINDING_ADDED + "','" + CoreNotificationType.BINDING_REMOVED + "','" + CoreNotificationType.CONSUMER_CREATED + "','" + CoreNotificationType.CONSUMER_CLOSED + "','" + CoreNotificationType.PROPOSAL + "','" + CoreNotificationType.PROPOSAL_RESPONSE + "','" + CoreNotificationType.UNPROPOSAL + "') AND " + ManagementHelper.HDR_DISTANCE + "<" + flowRecord.getMaxHops() + " AND (" + createSelectorFromAddress(appendIgnoresToFilter(flowRecord.getAddress())) + ")");
sessionConsumer.createTemporaryQueue(managementNotificationAddress, notifQueueName, filter);
notifConsumer = sessionConsumer.createConsumer(notifQueueName);
notifConsumer.setMessageHandler(flowRecord);
sessionConsumer.start();
ClientMessage message = sessionConsumer.createMessage(false);
if (logger.isTraceEnabled()) {
logger.trace("Requesting sendQueueInfoToQueue through " + this, new Exception("trace"));
}
ManagementHelper.putOperationInvocation(message, ResourceNames.BROKER, "sendQueueInfoToQueue", notifQueueName.toString(), flowRecord.getAddress());
try (ClientProducer prod = sessionConsumer.createProducer(managementAddress)) {
if (logger.isDebugEnabled()) {
logger.debug("Cluster connection bridge on " + clusterConnection + " requesting information on queues");
}
prod.send(message);
}
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class MQTTInterceptorPropertiesTest method testCheckInterceptedMQTTMessageProperties.
@Test(timeout = 60000)
public void testCheckInterceptedMQTTMessageProperties() throws Exception {
final String addressQueue = name.getMethodName();
final String msgText = "Test intercepted message";
final boolean retained = true;
Map<String, Object> expectedProperties = new ArrayMap<>();
expectedProperties.put(ADDRESS, addressQueue);
expectedProperties.put(MESSAGE_TEXT, msgText);
expectedProperties.put(RETAINED, retained);
final MQTTClientProvider subscribeProvider = getMQTTClientProvider();
initializeConnection(subscribeProvider);
subscribeProvider.subscribe(addressQueue, AT_MOST_ONCE);
final CountDownLatch latch = new CountDownLatch(1);
MQTTInterceptor incomingInterceptor = new MQTTInterceptor() {
@Override
public boolean intercept(MqttMessage packet, RemotingConnection connection) throws ActiveMQException {
System.out.println("incoming");
if (packet.getClass() == MqttPublishMessage.class) {
return checkMessageProperties(packet, expectedProperties);
} else {
return true;
}
}
};
MQTTInterceptor outgoingInterceptor = new MQTTInterceptor() {
@Override
public boolean intercept(MqttMessage packet, RemotingConnection connection) throws ActiveMQException {
System.out.println("outgoing");
if (packet.getClass() == MqttPublishMessage.class) {
return checkMessageProperties(packet, expectedProperties);
} else {
return true;
}
}
};
server.getRemotingService().addIncomingInterceptor(incomingInterceptor);
server.getRemotingService().addOutgoingInterceptor(outgoingInterceptor);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
byte[] payload = subscribeProvider.receive(10000);
assertNotNull("Should get a message", payload);
latch.countDown();
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
final MQTTClientProvider publishProvider = getMQTTClientProvider();
initializeConnection(publishProvider);
publishProvider.publish(addressQueue, msgText.getBytes(), AT_MOST_ONCE, retained);
latch.await(10, TimeUnit.SECONDS);
subscribeProvider.disconnect();
publishProvider.disconnect();
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class CloseDestroyedConnectionTest method testClosingTemporaryTopicDeletesQueue.
@Test
public void testClosingTemporaryTopicDeletesQueue() throws JMSException, ActiveMQException {
conn = cf.createConnection();
Assert.assertEquals(1, server.getRemotingService().getConnections().size());
session1 = (ActiveMQSession) conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
ActiveMQTemporaryTopic topic = (ActiveMQTemporaryTopic) session1.createTemporaryTopic();
String address = topic.getAddress();
session1.close();
conn.close();
conn2 = cf.createConnection();
session2 = (ActiveMQSession) conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
ClientSession cs = session2.getCoreSession();
try {
cs.createConsumer(address);
fail("the address from the TemporaryTopic still exists!");
} catch (ActiveMQException e) {
assertEquals("expecting 'queue does not exist'", ActiveMQExceptionType.QUEUE_DOES_NOT_EXIST, e.getType());
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class AcceptorControlTest method testStartStop.
@Test
public void testStartStop() throws Exception {
TransportConfiguration acceptorConfig = new TransportConfiguration(InVMAcceptorFactory.class.getName(), new HashMap<String, Object>(), RandomUtil.randomString());
Configuration config = createBasicConfig().addAcceptorConfiguration(acceptorConfig);
ActiveMQServer service = createServer(false, config);
service.setMBeanServer(mbeanServer);
service.start();
AcceptorControl acceptorControl = createManagementControl(acceptorConfig.getName());
// started by the server
Assert.assertTrue(acceptorControl.isStarted());
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
Assert.assertNotNull(session);
session.close();
acceptorControl.stop();
Assert.assertFalse(acceptorControl.isStarted());
try {
sf.createSession(false, true, true);
Assert.fail("acceptor must not accept connections when stopped accepting");
} catch (ActiveMQException e) {
}
acceptorControl.start();
Assert.assertTrue(acceptorControl.isStarted());
locator = createInVMNonHALocator();
sf = createSessionFactory(locator);
session = sf.createSession(false, true, true);
Assert.assertNotNull(session);
session.close();
acceptorControl.stop();
Assert.assertFalse(acceptorControl.isStarted());
try {
sf.createSession(false, true, true);
Assert.fail("acceptor must not accept connections when stopped accepting");
} catch (ActiveMQException e) {
}
}
Aggregations