use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class ClusterManager method deployBridge.
public synchronized void deployBridge(final BridgeConfiguration config) throws Exception {
if (config.getName() == null) {
ActiveMQServerLogger.LOGGER.bridgeNotUnique();
return;
}
if (config.getQueueName() == null) {
ActiveMQServerLogger.LOGGER.bridgeNoQueue(config.getName());
return;
}
if (config.getForwardingAddress() == null) {
ActiveMQServerLogger.LOGGER.bridgeNoForwardAddress(config.getName());
}
if (bridges.containsKey(config.getName())) {
ActiveMQServerLogger.LOGGER.bridgeAlreadyDeployed(config.getName());
return;
}
Transformer transformer = server.getServiceRegistry().getBridgeTransformer(config.getName(), config.getTransformerConfiguration());
Binding binding = postOffice.getBinding(new SimpleString(config.getQueueName()));
if (binding == null) {
ActiveMQServerLogger.LOGGER.bridgeQueueNotFound(config.getQueueName(), config.getName());
return;
}
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.beforeDeployBridge(config));
}
Queue queue = (Queue) binding.getBindable();
ServerLocatorInternal serverLocator;
if (config.getDiscoveryGroupName() != null) {
DiscoveryGroupConfiguration discoveryGroupConfiguration = configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName());
if (discoveryGroupConfiguration == null) {
ActiveMQServerLogger.LOGGER.bridgeNoDiscoveryGroup(config.getDiscoveryGroupName());
return;
}
if (config.isHA()) {
serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(discoveryGroupConfiguration);
} else {
serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration);
}
} else {
TransportConfiguration[] tcConfigs = configuration.getTransportConfigurations(config.getStaticConnectors());
if (tcConfigs == null) {
ActiveMQServerLogger.LOGGER.bridgeCantFindConnectors(config.getName());
return;
}
if (config.isHA()) {
serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(tcConfigs);
} else {
serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(tcConfigs);
}
}
serverLocator.setIdentity("Bridge " + config.getName());
serverLocator.setConfirmationWindowSize(config.getConfirmationWindowSize());
// We are going to manually retry on the bridge in case of failure
serverLocator.setReconnectAttempts(0);
serverLocator.setInitialConnectAttempts(0);
serverLocator.setRetryInterval(config.getRetryInterval());
serverLocator.setMaxRetryInterval(config.getMaxRetryInterval());
serverLocator.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier());
serverLocator.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod());
serverLocator.setConnectionTTL(config.getConnectionTTL());
serverLocator.setBlockOnDurableSend(!config.isUseDuplicateDetection());
serverLocator.setBlockOnNonDurableSend(!config.isUseDuplicateDetection());
serverLocator.setMinLargeMessageSize(config.getMinLargeMessageSize());
serverLocator.setProducerWindowSize(config.getProducerWindowSize());
// This will be set to 30s unless it's changed from embedded / testing
// there is no reason to exception the config for this timeout
// since the Bridge is supposed to be non-blocking and fast
// We may expose this if we find a good use case
serverLocator.setCallTimeout(config.getCallTimeout());
serverLocator.addIncomingInterceptor(new IncomingInterceptorLookingForExceptionMessage(this, executor));
if (!config.isUseDuplicateDetection()) {
logger.debug("Bridge " + config.getName() + " is configured to not use duplicate detecion, it will send messages synchronously");
}
clusterLocators.add(serverLocator);
Bridge bridge = new BridgeImpl(serverLocator, config.getInitialConnectAttempts(), config.getReconnectAttempts(), config.getReconnectAttemptsOnSameNode(), config.getRetryInterval(), config.getRetryIntervalMultiplier(), config.getMaxRetryInterval(), nodeManager.getUUID(), new SimpleString(config.getName()), queue, executorFactory.getExecutor(), FilterImpl.createFilter(config.getFilterString()), SimpleString.toSimpleString(config.getForwardingAddress()), scheduledExecutor, transformer, config.isUseDuplicateDetection(), config.getUser(), config.getPassword(), server);
bridges.put(config.getName(), bridge);
managementService.registerBridge(bridge, config);
bridge.start();
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.afterDeployBridge(bridge));
}
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class MQTTRetainMessageManager method addRetainedMessagesToQueue.
// SEND to Queue.
void addRetainedMessagesToQueue(Queue queue, String address) throws Exception {
// The address filter that matches all retained message queues.
String retainAddress = MQTTUtil.convertMQTTAddressFilterToCoreRetain(address, session.getWildcardConfiguration());
BindingQueryResult bindingQueryResult = session.getServerSession().executeBindingQuery(new SimpleString(retainAddress));
// Iterate over all matching retain queues and add the queue
Transaction tx = session.getServerSession().newTransaction();
try {
synchronized (queue) {
for (SimpleString retainedQueueName : bindingQueryResult.getQueueNames()) {
Queue retainedQueue = session.getServer().locateQueue(retainedQueueName);
try (LinkedListIterator<MessageReference> i = retainedQueue.iterator()) {
if (i.hasNext()) {
Message message = i.next().getMessage().copy(session.getServer().getStorageManager().generateID());
sendToQueue(message, queue, tx);
}
}
}
}
} catch (Throwable t) {
tx.rollback();
throw t;
}
tx.commit();
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class MQTTSubscriptionManager method createQueueForSubscription.
/**
* Creates a Queue if it doesn't already exist, based on a topic and address. Returning the queue name.
*/
private Queue createQueueForSubscription(String address, int qos) throws Exception {
// Check to see if a subscription queue already exists.
SimpleString queue = getQueueNameForTopic(address);
Queue q = session.getServer().locateQueue(queue);
// The queue does not exist so we need to create it.
if (q == null) {
SimpleString sAddress = SimpleString.toSimpleString(address);
// Check we can auto create queues.
BindingQueryResult bindingQueryResult = session.getServerSession().executeBindingQuery(sAddress);
if (!bindingQueryResult.isAutoCreateQueues()) {
throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(sAddress);
}
// Check that the address exists, if not we try to auto create it.
AddressInfo addressInfo = session.getServerSession().getAddress(sAddress);
if (addressInfo == null) {
if (!bindingQueryResult.isAutoCreateAddresses()) {
throw ActiveMQMessageBundle.BUNDLE.addressDoesNotExist(SimpleString.toSimpleString(address));
}
addressInfo = session.getServerSession().createAddress(SimpleString.toSimpleString(address), RoutingType.MULTICAST, true);
}
return findOrCreateQueue(bindingQueryResult, addressInfo, queue, qos);
}
return q;
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class MQTTSubscriptionManager method start.
synchronized void start() throws Exception {
for (MqttTopicSubscription subscription : session.getSessionState().getSubscriptions()) {
String coreAddress = MQTTUtil.convertMQTTAddressFilterToCore(subscription.topicName(), session.getWildcardConfiguration());
Queue q = createQueueForSubscription(coreAddress, subscription.qualityOfService().value());
createConsumerForSubscriptionQueue(q, subscription.topicName(), subscription.qualityOfService().value());
}
}
use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.
the class OpenWireConnection method removeDestination.
public void removeDestination(ActiveMQDestination dest) throws Exception {
if (dest.isQueue()) {
try {
server.destroyQueue(new SimpleString(dest.getPhysicalName()), getRemotingConnection());
} catch (ActiveMQNonExistentQueueException neq) {
// this is ok, ActiveMQ 5 allows this and will actually do it quite often
ActiveMQServerLogger.LOGGER.debug("queue never existed");
}
} else {
Bindings bindings = server.getPostOffice().getBindingsForAddress(new SimpleString(dest.getPhysicalName()));
for (Binding binding : bindings.getBindings()) {
Queue b = (Queue) binding.getBindable();
if (b.getConsumerCount() > 0) {
throw new Exception("Destination still has an active subscription: " + dest.getPhysicalName());
}
if (b.isDurable()) {
throw new Exception("Destination still has durable subscription: " + dest.getPhysicalName());
}
b.deleteQueue();
}
}
if (!AdvisorySupport.isAdvisoryTopic(dest)) {
AMQConnectionContext context = getContext();
DestinationInfo advInfo = new DestinationInfo(context.getConnectionId(), DestinationInfo.REMOVE_OPERATION_TYPE, dest);
ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(dest);
protocolManager.fireAdvisory(context, topic, advInfo);
}
}
Aggregations