Java Code Examples for org.apache.activemq.broker.BrokerService#setDestinationPolicy()

The following examples show how to use org.apache.activemq.broker.BrokerService#setDestinationPolicy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageGroupConfigTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public MessageGroupMap doTestGroupConfiguration(String type, Class classType) throws Exception {
   broker = new BrokerService();

   PolicyEntry defaultEntry = new PolicyEntry();
   defaultEntry.setMessageGroupMapFactoryType(type);
   PolicyMap policyMap = new PolicyMap();
   policyMap.setDefaultEntry(defaultEntry);
   broker.setDestinationPolicy(policyMap);
   broker.start();
   super.topic = false;
   ActiveMQDestination destination = (ActiveMQDestination) createDestination("org.apache.foo");
   Queue brokerDestination = (Queue) broker.getDestination(destination);

   assertNotNull(brokerDestination);
   MessageGroupMap messageGroupMap = brokerDestination.getMessageGroupOwners();
   assertNotNull(messageGroupMap);
   assertTrue(messageGroupMap.getClass().isAssignableFrom(classType));
   return messageGroupMap;
}
 
Example 2
Source File: MessageGroupReconnectDistributionTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected BrokerService createBroker() throws Exception {
   BrokerService service = new BrokerService();
   service.setAdvisorySupport(false);
   service.setPersistent(false);
   service.setUseJmx(true);

   PolicyMap policyMap = new PolicyMap();
   PolicyEntry policy = new PolicyEntry();
   policy.setUseConsumerPriority(consumerPriority);
   policy.setMessageGroupMapFactoryType("cached?cacheSize=" + (numConsumers - 1));
   policyMap.setDefaultEntry(policy);
   service.setDestinationPolicy(policyMap);

   connector = service.addConnector("tcp://localhost:0");
   return service;
}
 
Example 3
Source File: MessageGroupDelayedTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected BrokerService createBroker() throws Exception {
   BrokerService service = new BrokerService();
   service.setPersistent(false);
   service.setUseJmx(false);

   // Setup a destination policy where it takes only 1 message at a time.
   PolicyMap policyMap = new PolicyMap();
   PolicyEntry policy = new PolicyEntry();
   log.info("testing with consumersBeforeDispatchStarts=" + consumersBeforeDispatchStarts + " and timeBeforeDispatchStarts=" + timeBeforeDispatchStarts);
   policy.setConsumersBeforeDispatchStarts(consumersBeforeDispatchStarts);
   policy.setTimeBeforeDispatchStarts(timeBeforeDispatchStarts);
   policyMap.setDefaultEntry(policy);
   service.setDestinationPolicy(policyMap);

   connector = service.addConnector("tcp://localhost:0");
   return service;
}
 
Example 4
Source File: SimpleNonPersistentQueueTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void configureBroker(BrokerService answer, String uri) throws Exception {
   // answer.setPersistent(false);
   final List<PolicyEntry> policyEntries = new ArrayList<>();
   final PolicyEntry entry = new PolicyEntry();
   entry.setQueue(">");
   entry.setMemoryLimit(1024 * 1024 * 1); // Set to 1 MB
   entry.setOptimizedDispatch(true);
   entry.setLazyDispatch(true);
   policyEntries.add(entry);

   final PolicyMap policyMap = new PolicyMap();
   policyMap.setPolicyEntries(policyEntries);
   answer.setDestinationPolicy(policyMap);
   super.configureBroker(answer, uri);
}
 
Example 5
Source File: DiscriminatingConsumerLoadTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
   broker = new BrokerService();
   broker.setPersistent(false);

   // workaround is to ensure sufficient dispatch buffer for the destination
   PolicyMap policyMap = new PolicyMap();
   PolicyEntry defaultPolicy = new PolicyEntry();
   defaultPolicy.setMaxPageSize(testSize);
   policyMap.setDefaultEntry(defaultPolicy);
   broker.setDestinationPolicy(policyMap);
   broker.start();

   super.setUp();
   this.producerConnection = this.createConnection();
   this.consumerConnection = this.createConnection();
}
 
Example 6
Source File: AdvisoryTests.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void configureBroker(BrokerService answer) throws Exception {
   answer.setPersistent(false);
   PolicyEntry policy = new PolicyEntry();
   policy.setAdvisoryForFastProducers(true);
   policy.setAdvisoryForConsumed(true);
   policy.setAdvisoryForDelivery(true);
   policy.setAdvisoryForDiscardingMessages(true);
   policy.setAdvisoryForSlowConsumers(true);
   policy.setAdvisoryWhenFull(true);
   policy.setProducerFlowControl(false);
   ConstantPendingMessageLimitStrategy strategy = new ConstantPendingMessageLimitStrategy();
   strategy.setLimit(10);
   policy.setPendingMessageLimitStrategy(strategy);
   PolicyMap pMap = new PolicyMap();
   pMap.setDefaultEntry(policy);

   answer.setDestinationPolicy(pMap);
   answer.addConnector(bindAddress);
   answer.setDeleteAllMessagesOnStartup(true);
}
 
Example 7
Source File: TopicSubscriptionSlowConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private BrokerService createBroker() throws Exception {
   BrokerService broker = new BrokerService();
   broker.setBrokerName("localhost");
   broker.setUseJmx(true);
   broker.setDeleteAllMessagesOnStartup(true);
   broker.addConnector("vm://localhost");

   PolicyMap policyMap = new PolicyMap();
   PolicyEntry defaultEntry = new PolicyEntry();
   defaultEntry.setAdvisoryForSlowConsumers(true);

   policyMap.setDefaultEntry(defaultEntry);

   broker.setDestinationPolicy(policyMap);
   broker.start();
   broker.waitUntilStarted();
   return broker;
}
 
Example 8
Source File: QueueMemoryFullMultiBrokersTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void applyMemoryLimitPolicy(BrokerService broker) {
   final SystemUsage memoryManager = new SystemUsage();
   memoryManager.getMemoryUsage().setLimit(1024 * 50); // 50 MB
   broker.setSystemUsage(memoryManager);

   final List<PolicyEntry> policyEntries = new ArrayList<>();
   final PolicyEntry entry = new PolicyEntry();
   entry.setQueue(">");
   entry.setMemoryLimit(1024 * 4); // Set to 2 kb
   entry.setPendingQueuePolicy(new VMPendingQueueMessageStoragePolicy());
   policyEntries.add(entry);

   final PolicyMap policyMap = new PolicyMap();
   policyMap.setPolicyEntries(policyEntries);
   broker.setDestinationPolicy(policyMap);

}
 
Example 9
Source File: DiscardingDeadLetterPolicyTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected BrokerService createBroker() throws Exception {
   BrokerService broker = super.createBroker();

   PolicyEntry policy = new PolicyEntry();
   DeadLetterStrategy strategy = new DiscardingDeadLetterStrategy();
   strategy.setProcessNonPersistent(true);
   policy.setDeadLetterStrategy(strategy);

   PolicyMap pMap = new PolicyMap();
   pMap.setDefaultEntry(policy);

   broker.setDestinationPolicy(pMap);

   return broker;
}
 
Example 10
Source File: TwoBrokerQueueClientsReconnectTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureBroker(BrokerService broker) {
   PolicyMap policyMap = new PolicyMap();
   PolicyEntry defaultEntry = new PolicyEntry();
   defaultEntry.setEnableAudit(false);
   policyMap.setDefaultEntry(defaultEntry);
   broker.setDestinationPolicy(policyMap);
}
 
Example 11
Source File: ExpiredMessagesWithNoConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void doCreateBroker(boolean memoryLimit, int expireMessagesPeriod) throws Exception {
   broker = new BrokerService();
   broker.setBrokerName("localhost");
   broker.setUseJmx(true);
   broker.setDeleteAllMessagesOnStartup(true);
   broker.addConnector("tcp://localhost:0");

   PolicyMap policyMap = new PolicyMap();
   PolicyEntry defaultEntry = new PolicyEntry();
   defaultEntry.setOptimizedDispatch(optimizedDispatch);
   defaultEntry.setExpireMessagesPeriod(expireMessagesPeriod);
   defaultEntry.setMaxExpirePageSize(800);

   defaultEntry.setPendingQueuePolicy(pendingQueuePolicy);

   if (memoryLimit) {
      // so memory is not consumed by DLQ turn if off
      defaultEntry.setDeadLetterStrategy(null);
      defaultEntry.setMemoryLimit(200 * 1000);
   }

   policyMap.setDefaultEntry(defaultEntry);

   broker.setDestinationPolicy(policyMap);
   broker.start();
   broker.waitUntilStarted();

   connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString();
}
 
Example 12
Source File: JmsProducerFlowControlFailIfNoSpaceTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureBrokerPolicies(BrokerService brokerService) {

    PolicyEntry policy = new PolicyEntry();
    policy.setMemoryLimit(1);
    policy.setPendingSubscriberPolicy(new VMPendingSubscriberMessageStoragePolicy());
    policy.setPendingQueuePolicy(new VMPendingQueueMessageStoragePolicy());
    policy.setProducerFlowControl(true);

    PolicyMap policyMap = new PolicyMap();
    policyMap.setDefaultEntry(policy);

    brokerService.setDestinationPolicy(policyMap);
    brokerService.getSystemUsage().setSendFailIfNoSpace(true);
}
 
Example 13
Source File: StrictOrderDispatchPolicyTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected BrokerService createBroker() throws Exception {
   BrokerService broker = super.createBroker();

   PolicyEntry policy = new PolicyEntry();
   policy.setDispatchPolicy(new StrictOrderDispatchPolicy());

   PolicyMap pMap = new PolicyMap();
   pMap.setDefaultEntry(policy);

   broker.setDestinationPolicy(pMap);

   return broker;
}
 
Example 14
Source File: BrokerExtension.java    From james-project with Apache License 2.0 5 votes vote down vote up
private static void enablePrioritySupport(BrokerService aBroker, String queueName) {
    PolicyMap pMap = new PolicyMap();
    PolicyEntry entry = new PolicyEntry();
    entry.setPrioritizedMessages(true);
    entry.setQueue(queueName);
    pMap.setPolicyEntries(ImmutableList.of(entry));
    aBroker.setDestinationPolicy(pMap);
}
 
Example 15
Source File: DeadLetterTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createBroker() throws Exception {
   BrokerService broker = new BrokerService();
   broker.setPersistent(false);
   PolicyEntry policy = new PolicyEntry();
   DeadLetterStrategy defaultDeadLetterStrategy = policy.getDeadLetterStrategy();
   if (defaultDeadLetterStrategy != null) {
      defaultDeadLetterStrategy.setProcessNonPersistent(true);
   }
   PolicyMap pMap = new PolicyMap();
   pMap.setDefaultEntry(policy);
   broker.setDestinationPolicy(pMap);
   return broker;
}
 
Example 16
Source File: BrokerNetworkWithStuckMessagesTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void configureBroker(BrokerService broker) {
   PolicyMap policyMap = new PolicyMap();
   PolicyEntry defaultEntry = new PolicyEntry();
   defaultEntry.setExpireMessagesPeriod(0);
   ConditionalNetworkBridgeFilterFactory filterFactory = new ConditionalNetworkBridgeFilterFactory();
   filterFactory.setReplayWhenNoConsumers(true);
   defaultEntry.setNetworkBridgeFilterFactory(filterFactory);
   policyMap.setDefaultEntry(defaultEntry);
   broker.setDestinationPolicy(policyMap);
}
 
Example 17
Source File: AbstractElasticSearchActiveMQTest.java    From camunda-bpm-elasticsearch with Apache License 2.0 5 votes vote down vote up
protected BrokerService createBroker() {
  BrokerService brokerService = new BrokerService();
  brokerService.setPersistent(false);
  brokerService.setUseJmx(false);

  PolicyMap policyMap = new PolicyMap();
  PolicyEntry policy = new PolicyEntry();
  policy.setConsumersBeforeDispatchStarts(2);
  policy.setTimeBeforeDispatchStarts(1000);
  policyMap.setDefaultEntry(policy);

  brokerService.setDestinationPolicy(policyMap);

  return brokerService;
}
 
Example 18
Source File: CursorQueueStoreTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureBroker(BrokerService answer) throws Exception {
   PolicyEntry policy = new PolicyEntry();
   policy.setPendingQueuePolicy(new StorePendingQueueMessageStoragePolicy());
   PolicyMap pMap = new PolicyMap();
   pMap.setDefaultEntry(policy);
   answer.setDestinationPolicy(pMap);
   answer.setDeleteAllMessagesOnStartup(true);
   answer.addConnector(bindAddress);
   answer.setDeleteAllMessagesOnStartup(true);
}
 
Example 19
Source File: TimeStampingBrokerPluginTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   TimeStampingBrokerPlugin tsbp = new TimeStampingBrokerPlugin();
   tsbp.setZeroExpirationOverride(expiry);
   tsbp.setTtlCeiling(expiry);

   broker = new BrokerService();
   broker.setPersistent(false);
   broker.setUseJmx(true);
   broker.setPlugins(new BrokerPlugin[]{tsbp});
   tcpConnector = broker.addConnector("tcp://localhost:0");

   // Add policy and individual DLQ strategy
   PolicyEntry policy = new PolicyEntry();
   DeadLetterStrategy strategy = new IndividualDeadLetterStrategy();
   strategy.setProcessExpired(true);
   ((IndividualDeadLetterStrategy) strategy).setUseQueueForQueueMessages(true);
   ((IndividualDeadLetterStrategy) strategy).setQueuePrefix("DLQ.");
   strategy.setProcessNonPersistent(true);
   policy.setDeadLetterStrategy(strategy);

   PolicyMap pMap = new PolicyMap();
   pMap.setDefaultEntry(policy);

   broker.setDestinationPolicy(pMap);

   broker.start();
   // Create a ConnectionFactory
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(tcpConnector.getConnectUri());

   // Create a Connection
   connection = connectionFactory.createConnection();
   connection.start();

   // Create a Session
   session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

   // Create the destination Queue
   destination = session.createQueue(queue);

   // Create a MessageProducer from the Session to the Topic or Queue
   producer = session.createProducer(destination);
   producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
}
 
Example 20
Source File: IgniteMqttStreamerTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
@Override public void beforeTest() throws Exception {
    grid().<Integer, String>getOrCreateCache(defaultCacheConfiguration());

    // find an available local port
    try (ServerSocket ss = new ServerSocket(0)) {
        port = ss.getLocalPort();
    }

    // create the broker
    broker = new BrokerService();
    broker.setDeleteAllMessagesOnStartup(true);
    broker.setPersistent(false);
    broker.setPersistenceAdapter(null);
    broker.setPersistenceFactory(null);

    PolicyMap plcMap = new PolicyMap();
    PolicyEntry plc = new PolicyEntry();

    plc.setQueuePrefetch(1);

    broker.setDestinationPolicy(plcMap);
    broker.getDestinationPolicy().setDefaultEntry(plc);
    broker.setSchedulerSupport(false);

    // add the MQTT transport connector to the broker
    broker.addConnector("mqtt://localhost:" + port);
    broker.setStartAsync(false);
    broker.start(true);

    // create the broker URL
    brokerUrl = "tcp://localhost:" + port;

    // create the client and connect
    client = new MqttClient(brokerUrl, UUID.randomUUID().toString(), new MemoryPersistence());

    client.connect();

    // create mqtt streamer
    dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME);

    streamer = createMqttStreamer(dataStreamer);
}