Пример #1
0
  // backup node becomes live
  public synchronized void activate() {
    if (backup) {
      backup = false;

      for (BroadcastGroup broadcastGroup : broadcastGroups.values()) {
        try {
          broadcastGroup.start();
          broadcastGroup.activate();
        } catch (Exception e) {
          log.warn("unable to start broadcast group " + broadcastGroup.getName(), e);
        }
      }

      for (ClusterConnection clusterConnection : clusterConnections.values()) {
        try {
          clusterConnection.activate();
        } catch (Exception e) {
          log.warn("unable to start cluster connection " + clusterConnection.getName(), e);
        }
      }

      for (Bridge bridge : bridges.values()) {
        try {
          bridge.start();
        } catch (Exception e) {
          log.warn("unable to start bridge " + bridge.getName(), e);
        }
      }
    }
  }
Пример #2
0
  public void destroyBridge(final String name) throws Exception {
    Bridge bridge;

    synchronized (this) {
      bridge = bridges.remove(name);
      if (bridge != null) {
        bridge.stop();
        managementService.unregisterBridge(name);
      }
    }
    if (bridge != null) {
      bridge.flushExecutor();
    }
  }
Пример #3
0
 // for testing
 public void clear() {
   for (Bridge bridge : bridges.values()) {
     try {
       bridge.stop();
     } catch (Exception e) {
       log.warn(e.getMessage(), e);
     }
   }
   bridges.clear();
   for (ClusterConnection clusterConnection : clusterConnections.values()) {
     try {
       clusterConnection.stop();
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   clearClusterConnections();
 }
Пример #4
0
  public void stop() throws Exception {
    synchronized (this) {
      if (!started) {
        return;
      }

      if (clustered) {
        for (BroadcastGroup group : broadcastGroups.values()) {
          group.stop();
          managementService.unregisterBroadcastGroup(group.getName());
        }

        broadcastGroups.clear();

        for (ClusterConnection clusterConnection : clusterConnections.values()) {
          clusterConnection.stop();
          managementService.unregisterCluster(clusterConnection.getName().toString());
        }
      }

      for (Bridge bridge : bridges.values()) {
        bridge.stop();
        managementService.unregisterBridge(bridge.getName().toString());
      }

      bridges.clear();
    }

    for (ServerLocatorInternal clusterLocator : clusterLocators) {
      try {
        clusterLocator.close();
      } catch (Exception e) {
        log.warn(
            "Error closing serverLocator=" + clusterLocator + ", message=" + e.getMessage(), e);
      }
    }
    clusterLocators.clear();
    started = false;

    clearClusterConnections();
  }
Пример #5
0
  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();
    }
  }
Пример #6
0
  @Test
  public void testStartStop() throws Exception {
    Map<String, Object> server0Params = new HashMap<String, Object>();
    HornetQServer server0 = createClusteredServerWithParams(isNetty(), 0, true, server0Params);

    Map<String, Object> server1Params = new HashMap<String, Object>();
    if (isNetty()) {
      server1Params.put(
          "port", org.hornetq.core.remoting.impl.netty.TransportConstants.DEFAULT_PORT + 1);
    } else {
      server1Params.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
    }
    HornetQServer server1 = createClusteredServerWithParams(isNetty(), 1, true, server1Params);
    ServerLocator locator = null;
    try {
      final String testAddress = "testAddress";
      final String queueName0 = "queue0";
      final String forwardAddress = "forwardAddress";
      final String queueName1 = "queue1";

      Map<String, TransportConfiguration> connectors =
          new HashMap<String, TransportConfiguration>();
      TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
      TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
      connectors.put(server1tc.getName(), server1tc);

      server0.getConfiguration().setConnectorConfigurations(connectors);

      ArrayList<String> staticConnectors = new ArrayList<String>();
      staticConnectors.add(server1tc.getName());

      final String bridgeName = "bridge1";

      BridgeConfiguration bridgeConfiguration =
          new BridgeConfiguration()
              .setName(bridgeName)
              .setQueueName(queueName0)
              .setForwardingAddress(forwardAddress)
              .setRetryInterval(1000)
              .setReconnectAttempts(0)
              .setReconnectAttemptsOnSameNode(0)
              .setConfirmationWindowSize(1024)
              .setStaticConnectors(staticConnectors);

      List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
      bridgeConfigs.add(bridgeConfiguration);
      server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);

      CoreQueueConfiguration queueConfig0 =
          new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
      List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<CoreQueueConfiguration>();
      queueConfigs0.add(queueConfig0);
      server0.getConfiguration().setQueueConfigurations(queueConfigs0);

      CoreQueueConfiguration queueConfig1 =
          new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName1);
      List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<CoreQueueConfiguration>();
      queueConfigs1.add(queueConfig1);
      server1.getConfiguration().setQueueConfigurations(queueConfigs1);

      server1.start();
      waitForServer(server1);

      server0.start();
      waitForServer(server0);

      locator = HornetQClient.createServerLocatorWithoutHA(server0tc, server1tc);
      ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);

      ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);

      ClientSession session0 = sf0.createSession(false, true, true);

      ClientSession session1 = sf1.createSession(false, true, true);

      ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));

      ClientConsumer consumer1 = session1.createConsumer(queueName1);

      session1.start();

      final int numMessages = 10;

      final SimpleString propKey = new SimpleString("testkey");

      for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(false);

        message.putIntProperty(propKey, i);

        producer0.send(message);
      }

      for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(200);

        Assert.assertNotNull(message);

        Assert.assertEquals(i, message.getObjectProperty(propKey));

        message.acknowledge();
      }

      Assert.assertNull(consumer1.receiveImmediate());

      Bridge bridge = server0.getClusterManager().getBridges().get(bridgeName);

      bridge.stop();

      bridge.flushExecutor();

      for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(false);

        message.putIntProperty(propKey, i);

        producer0.send(message);
      }

      Assert.assertNull(consumer1.receiveImmediate());

      bridge.start();

      for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(1000);

        Assert.assertNotNull(message);

        Assert.assertEquals(i, message.getObjectProperty(propKey));

        message.acknowledge();
      }

      Assert.assertNull(consumer1.receiveImmediate());

      session0.close();

      session1.close();

      sf0.close();

      sf1.close();
    } finally {
      if (locator != null) {
        locator.close();
      }

      server0.stop();

      server1.stop();
    }
  }