public void setStringProperty(final String name, final String value) throws JMSException { checkProperty(name, value); if (HornetQMessage.JMSXGROUPID.equals(name)) { message.putStringProperty( org.hornetq.api.core.Message.HDR_GROUP_ID, SimpleString.toSimpleString(value)); } else { message.putStringProperty(new SimpleString(name), SimpleString.toSimpleString(value)); } }
/** * deploy an element * * @param node the element to deploy * @throws Exception . */ @Override public void deploy(final Node node) throws Exception { CoreQueueConfiguration queueConfig = parser.parseQueueConfiguration(node); server.deployQueue( SimpleString.toSimpleString(queueConfig.getAddress()), SimpleString.toSimpleString(queueConfig.getName()), SimpleString.toSimpleString(queueConfig.getFilterString()), queueConfig.isDurable(), false); }
public Message putStringProperty(final String key, final String value) { properties.putSimpleStringProperty(new SimpleString(key), SimpleString.toSimpleString(value)); bufferValid = false; return this; }
public String getLastSentMessageID(String address) { Pair<UUID, AtomicLong> value = targetAddressInfos.get(SimpleString.toSimpleString(address)); if (value != null) { return value.getA().toString(); } else { return null; } }
public void addSubscription( long consumerID, String subscriptionID, String clientID, String durableSubscriptionName, String destination, String selector, String ack) throws Exception { SimpleString queue = SimpleString.toSimpleString(destination); int receiveCredits = consumerCredits; if (ack.equals(Stomp.Headers.Subscribe.AckModeValues.AUTO)) { receiveCredits = -1; } if (destination.startsWith("jms.topic")) { // subscribes to a topic if (durableSubscriptionName != null) { if (clientID == null) { throw BUNDLE.missingClientID(); } queue = SimpleString.toSimpleString(clientID + "." + durableSubscriptionName); QueueQueryResult query = session.executeQueueQuery(queue); if (!query.isExists()) { session.createQueue( SimpleString.toSimpleString(destination), queue, SimpleString.toSimpleString(selector), false, true); } } else { queue = UUIDGenerator.getInstance().generateSimpleStringUUID(); session.createQueue( SimpleString.toSimpleString(destination), queue, SimpleString.toSimpleString(selector), true, false); } ((ServerSessionImpl) session) .createConsumer(consumerID, queue, null, false, false, receiveCredits); } else { ((ServerSessionImpl) session) .createConsumer( consumerID, queue, SimpleString.toSimpleString(selector), false, false, receiveCredits); } StompSubscription subscription = new StompSubscription(subscriptionID, ack); subscriptions.put(consumerID, subscription); session.start(); }
/** * This will simulate what would happen with topic creationg where a single record is supposed to * be created on the journal * * @throws Exception */ @Test public void testDuplicateDestinationsOnTopic() throws Exception { for (int i = 0; i < 5; i++) { if (server.locateQueue(SimpleString.toSimpleString("jms.topic.tt")) == null) { server.createQueue( SimpleString.toSimpleString("jms.topic.tt"), SimpleString.toSimpleString("jms.topic.tt"), SimpleString.toSimpleString(HornetQServerImpl.GENERIC_IGNORED_FILTER), true, false); } server.stop(); SequentialFileFactory messagesFF = new NIOSequentialFileFactory(getBindingsDir(), null); JournalImpl messagesJournal = new JournalImpl(1024 * 1024, 2, 0, 0, messagesFF, "hornetq-bindings", "bindings", 1); messagesJournal.start(); LinkedList<RecordInfo> infos = new LinkedList<RecordInfo>(); messagesJournal.load(infos, null, null); int bindings = 0; for (RecordInfo info : infos) { if (info.getUserRecordType() == JournalRecordIds.QUEUE_BINDING_RECORD) { bindings++; } } assertEquals(1, bindings); System.out.println("Bindings: " + bindings); messagesJournal.stop(); if (i < 4) server.start(); } }
public boolean unsubscribe(String id, String durableSubscriptionName) throws Exception { Iterator<Entry<Long, StompSubscription>> iterator = subscriptions.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<Long, StompSubscription> entry = iterator.next(); long consumerID = entry.getKey(); StompSubscription sub = entry.getValue(); if (id != null && id.equals(sub.getID())) { iterator.remove(); session.closeConsumer(consumerID); SimpleString queueName; if (durableSubscriptionName != null && durableSubscriptionName.trim().length() != 0) { queueName = SimpleString.toSimpleString(id + "." + durableSubscriptionName); } else { queueName = SimpleString.toSimpleString(id); } QueueQueryResult query = session.executeQueueQuery(queueName); if (query.isExists()) { session.deleteQueue(queueName); } return true; } } return false; }
public synchronized void deployBridge(final BridgeConfiguration config, final boolean start) throws Exception { if (config.getName() == null) { ClusterManagerImpl.log.warn( "Must specify a unique name for each bridge. This one will not be deployed."); return; } if (config.getQueueName() == null) { ClusterManagerImpl.log.warn( "Must specify a queue name for each bridge. This one will not be deployed."); return; } if (config.getForwardingAddress() == null) { ClusterManagerImpl.log.debug( "Forward address is not specified. Will use original message address instead"); } if (bridges.containsKey(config.getName())) { ClusterManagerImpl.log.warn( "There is already a bridge with name " + config.getName() + " deployed. This one will not be deployed."); return; } Transformer transformer = instantiateTransformer(config.getTransformerClassName()); Binding binding = postOffice.getBinding(new SimpleString(config.getQueueName())); if (binding == null) { ClusterManagerImpl.log.warn( "No queue found with name " + config.getQueueName() + " bridge will not be deployed."); return; } Queue queue = (Queue) binding.getBindable(); ServerLocatorInternal serverLocator; if (config.getDiscoveryGroupName() != null) { DiscoveryGroupConfiguration discoveryGroupConfiguration = configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName()); if (discoveryGroupConfiguration == null) { ClusterManagerImpl.log.warn( "No discovery group configured with name '" + config.getDiscoveryGroupName() + "'. The bridge will not be deployed."); return; } if (config.isHA()) { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithHA(discoveryGroupConfiguration); } else { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration); } } else { TransportConfiguration[] tcConfigs = connectorNameListToArray(config.getStaticConnectors()); if (tcConfigs == null) { return; } if (config.isHA()) { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithHA(tcConfigs); } else { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithoutHA(tcConfigs); } } serverLocator.setConfirmationWindowSize(config.getConfirmationWindowSize()); // We are going to manually retry on the bridge in case of failure serverLocator.setReconnectAttempts(0); serverLocator.setInitialConnectAttempts(-1); serverLocator.setRetryInterval(config.getRetryInterval()); serverLocator.setMaxRetryInterval(config.getMaxRetryInterval()); serverLocator.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier()); serverLocator.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod()); serverLocator.setBlockOnDurableSend(!config.isUseDuplicateDetection()); serverLocator.setBlockOnNonDurableSend(!config.isUseDuplicateDetection()); serverLocator.setMinLargeMessageSize(config.getMinLargeMessageSize()); // disable flow control serverLocator.setProducerWindowSize(-1); // 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()); if (!config.isUseDuplicateDetection()) { log.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.getReconnectAttempts(), config.getRetryInterval(), config.getRetryIntervalMultiplier(), config.getMaxRetryInterval(), nodeUUID, new SimpleString(config.getName()), queue, executorFactory.getExecutor(), SimpleString.toSimpleString(config.getFilterString()), SimpleString.toSimpleString(config.getForwardingAddress()), scheduledExecutor, transformer, config.isUseDuplicateDetection(), config.getUser(), config.getPassword(), !backup, server.getStorageManager()); bridges.put(config.getName(), bridge); managementService.registerBridge(bridge, config); if (start) { bridge.start(); } }
static SimpleString asSimpleString(final ModelNode node, final String defVal) { return SimpleString.toSimpleString( node.getType() != ModelType.UNDEFINED ? node.asString() : defVal); }
public synchronized void deployBridge(final BridgeConfiguration config) throws Exception { if (config.getName() == null) { HornetQServerLogger.LOGGER.bridgeNotUnique(); return; } if (config.getQueueName() == null) { HornetQServerLogger.LOGGER.bridgeNoQueue(config.getName()); return; } if (config.getForwardingAddress() == null) { HornetQServerLogger.LOGGER.bridgeNoForwardAddress(config.getName()); } if (bridges.containsKey(config.getName())) { HornetQServerLogger.LOGGER.bridgeAlreadyDeployed(config.getName()); return; } Transformer transformer = instantiateTransformer(config.getTransformerClassName()); Binding binding = postOffice.getBinding(new SimpleString(config.getQueueName())); if (binding == null) { HornetQServerLogger.LOGGER.bridgeQueueNotFound(config.getQueueName(), config.getName()); return; } Queue queue = (Queue) binding.getBindable(); ServerLocatorInternal serverLocator; if (config.getDiscoveryGroupName() != null) { DiscoveryGroupConfiguration discoveryGroupConfiguration = configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName()); if (discoveryGroupConfiguration == null) { HornetQServerLogger.LOGGER.bridgeNoDiscoveryGroup(config.getDiscoveryGroupName()); return; } if (config.isHA()) { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithHA(discoveryGroupConfiguration); } else { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration); } } else { TransportConfiguration[] tcConfigs = connectorNameListToArray(config.getStaticConnectors()); if (tcConfigs == null) { HornetQServerLogger.LOGGER.bridgeCantFindConnectors(config.getName()); return; } if (config.isHA()) { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithHA(tcConfigs); } else { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithoutHA(tcConfigs); } } if (config.getForwardingAddress() != null) { AddressSettings addressConfig = configuration.getAddressesSettings().get(config.getForwardingAddress()); // The address config could be null on certain test cases or some Embedded environment if (addressConfig == null) { // We will certainly have this warning on testcases which is ok HornetQServerLogger.LOGGER.bridgeCantFindAddressConfig( config.getName(), config.getForwardingAddress()); } else { final int windowSize = config.getConfirmationWindowSize(); final long maxBytes = addressConfig.getMaxSizeBytes(); if (maxBytes != -1 && maxBytes < windowSize) { HornetQServerLogger.LOGGER.bridgeConfirmationWindowTooSmall( config.getName(), config.getForwardingAddress(), windowSize, maxBytes); } } } 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()); // disable flow control serverLocator.setProducerWindowSize(-1); // 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()); if (!config.isUseDuplicateDetection()) { HornetQServerLogger.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.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(), !backup, server.getStorageManager()); bridges.put(config.getName(), bridge); managementService.registerBridge(bridge, config); bridge.start(); }
@Test public void testSendTopic() throws Exception { Topic topic = createTopic("topic"); Connection conn = cf.createConnection(); try { conn.setClientID("someID"); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons = sess.createDurableSubscriber(topic, "someSub"); conn.start(); MessageProducer prod = sess.createProducer(topic); TextMessage msg1 = sess.createTextMessage("text"); prod.send(msg1); assertNotNull(cons.receive(5000)); conn.close(); StorageManager storage = server.getStorageManager(); for (int i = 0; i < 100; i++) { long txid = storage.generateUniqueID(); final Queue queue = new QueueImpl( storage.generateUniqueID(), SimpleString.toSimpleString("jms.topic.topic"), SimpleString.toSimpleString("jms.topic.topic"), FilterImpl.createFilter(HornetQServerImpl.GENERIC_IGNORED_FILTER), true, false, server.getScheduledPool(), server.getPostOffice(), storage, server.getAddressSettingsRepository(), server.getExecutorFactory().getExecutor()); LocalQueueBinding binding = new LocalQueueBinding(queue.getAddress(), queue, server.getNodeID()); storage.addQueueBinding(txid, binding); storage.commitBindings(txid); } jmsServer.stop(); jmsServer.start(); } finally { try { conn.close(); } catch (Throwable igonred) { } } }
public void close(final boolean failed) throws Exception { callback.removeReadyListener(this); setStarted(false); LargeMessageDeliverer del = largeMessageDeliverer; if (del != null) { del.finish(); } if (browseOnly) { browserDeliverer.close(); } else { messageQueue.removeConsumer(this); } session.removeConsumer(id); LinkedList<MessageReference> refs = cancelRefs(failed, false, null); Iterator<MessageReference> iter = refs.iterator(); Transaction tx = new TransactionImpl(storageManager); while (iter.hasNext()) { MessageReference ref = iter.next(); ref.getQueue().cancel(tx, ref); } tx.rollback(); if (!browseOnly) { TypedProperties props = new TypedProperties(); props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress()); props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName()); props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName()); props.putSimpleStringProperty( ManagementHelper.HDR_FILTERSTRING, filter == null ? null : filter.getFilterString()); props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance()); props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, messageQueue.getConsumerCount()); // HORNETQ-946 props.putSimpleStringProperty( ManagementHelper.HDR_USER, SimpleString.toSimpleString(session.getUsername())); props.putSimpleStringProperty( ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString( ((ServerSessionImpl) session).getRemotingConnection().getRemoteAddress())); props.putSimpleStringProperty( ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(session.getName())); Notification notification = new Notification(null, NotificationType.CONSUMER_CLOSED, props); managementService.sendNotification(notification); } }
public void createConsumer( final long consumerID, final SimpleString queueName, final SimpleString filterString, final boolean browseOnly, final boolean supportLargeMessage, final Integer credits) throws Exception { Binding binding = postOffice.getBinding(queueName); if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) { throw HornetQMessageBundle.BUNDLE.noSuchQueue(queueName); } securityStore.check(binding.getAddress(), CheckType.CONSUME, this); Filter filter = FilterImpl.createFilter(filterString); ServerConsumer consumer = new ServerConsumerImpl( consumerID, this, (QueueBinding) binding, filter, started, browseOnly, storageManager, callback, preAcknowledge, strictUpdateDeliveryCount, managementService, supportLargeMessage, credits); consumers.put(consumer.getID(), consumer); if (!browseOnly) { TypedProperties props = new TypedProperties(); props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress()); props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName()); props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName()); props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance()); Queue theQueue = (Queue) binding.getBindable(); props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount()); // HORNETQ-946 props.putSimpleStringProperty( ManagementHelper.HDR_USER, SimpleString.toSimpleString(username)); props.putSimpleStringProperty( ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString(this.remotingConnection.getRemoteAddress())); props.putSimpleStringProperty( ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(name)); if (filterString != null) { props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString); } Notification notification = new Notification(null, CONSUMER_CREATED, props); if (HornetQServerLogger.LOGGER.isDebugEnabled()) { HornetQServerLogger.LOGGER.debug( "Session with user="******", connection=" + this.remotingConnection + " created a consumer on queue " + queueName + ", filter = " + filterString); } managementService.sendNotification(notification); } }