public void process(VirtualHost virtualHost, ServerMessage message) {
    String exchangeName = message.getMessageHeader().getReplyToExchange();
    String routingKey = message.getMessageHeader().getReplyToRoutingKey();

    IApplicationRegistry appRegistry = virtualHost.getApplicationRegistry();
    QMFService service = appRegistry.getQMFService();

    QMFPackage qmfPackage = service.getPackage(_packageName);
    QMFClass qmfClass = qmfPackage.getQMFClass(_className);

    QMFCommand[] commands = new QMFCommand[2];
    commands[0] = new QMFSchemaResponseCommand(this, qmfClass);
    commands[1] = new QMFCommandCompletionCommand(this);

    Exchange exchange = virtualHost.getExchangeRegistry().getExchange(exchangeName);

    for (QMFCommand cmd : commands) {
      QMFMessage responseMessage = new QMFMessage(routingKey, cmd);

      ArrayList<? extends BaseQueue> queues = exchange.route(responseMessage);

      for (BaseQueue q : queues) {
        try {
          q.enqueue(responseMessage);
        } catch (AMQException e) {
          e.printStackTrace(); // To change body of catch statement use File | Settings | File
          // Templates.
        }
      }
    }
  }
Пример #2
0
  public void testCreateQueueAMQQueueWithAlternateExchange() throws Exception {
    Exchange alternateExchange = createTestAlternateExchange();

    AMQQueue queue = createTestQueue(getName(), getName() + "Owner", true, alternateExchange);
    _store.createQueue(queue);

    reopenStore();
    verify(_queueRecoveryHandler)
        .queue(_queueId, getName(), getName() + "Owner", true, null, alternateExchange.getId());
  }
Пример #3
0
  public void testUpdateQueueAlternateExchange() throws Exception {
    // create queue
    AMQQueue queue = createTestQueue(getName(), getName() + "Owner", true);
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("x-qpid-dlq-enabled", Boolean.TRUE);
    attributes.put("x-qpid-maximum-delivery-count", new Integer(10));
    FieldTable arguments = FieldTable.convertToFieldTable(attributes);
    _store.createQueue(queue, arguments);

    // update the queue to have exclusive=false
    Exchange alternateExchange = createTestAlternateExchange();
    queue = createTestQueue(getName(), getName() + "Owner", false, alternateExchange);
    _store.updateQueue(queue);

    reopenStore();
    verify(_queueRecoveryHandler)
        .queue(
            _queueId, getName(), getName() + "Owner", false, arguments, alternateExchange.getId());
  }
Пример #4
0
  public void setUp() throws Exception {
    super.setUp();

    _queueId = UUIDGenerator.generateRandomUUID();
    _exchangeId = UUIDGenerator.generateRandomUUID();

    _storeName = getName();
    _storePath = TMP_FOLDER + File.separator + _storeName;
    FileUtils.delete(new File(_storePath), true);
    setTestSystemProperty("QPID_WORK", TMP_FOLDER);
    _configuration = mock(Configuration.class);
    _recoveryHandler = mock(ConfigurationRecoveryHandler.class);
    _queueRecoveryHandler = mock(QueueRecoveryHandler.class);
    _exchangeRecoveryHandler = mock(ExchangeRecoveryHandler.class);
    _bindingRecoveryHandler = mock(BindingRecoveryHandler.class);
    _storedMessageRecoveryHandler = mock(StoredMessageRecoveryHandler.class);
    _logRecoveryHandler = mock(TransactionLogRecoveryHandler.class);
    _messageStoreRecoveryHandler = mock(MessageStoreRecoveryHandler.class);
    _queueEntryRecoveryHandler =
        mock(TransactionLogRecoveryHandler.QueueEntryRecoveryHandler.class);
    _dtxRecordRecoveryHandler = mock(TransactionLogRecoveryHandler.DtxRecordRecoveryHandler.class);

    when(_messageStoreRecoveryHandler.begin()).thenReturn(_storedMessageRecoveryHandler);
    when(_recoveryHandler.begin(isA(MessageStore.class))).thenReturn(_exchangeRecoveryHandler);
    when(_exchangeRecoveryHandler.completeExchangeRecovery()).thenReturn(_queueRecoveryHandler);
    when(_queueRecoveryHandler.completeQueueRecovery()).thenReturn(_bindingRecoveryHandler);
    when(_logRecoveryHandler.begin(any(MessageStore.class))).thenReturn(_queueEntryRecoveryHandler);
    when(_queueEntryRecoveryHandler.completeQueueEntryRecovery())
        .thenReturn(_dtxRecordRecoveryHandler);
    when(_exchange.getNameShortString()).thenReturn(AMQShortString.valueOf(EXCHANGE_NAME));
    when(_exchange.getId()).thenReturn(_exchangeId);
    when(_configuration.getString(eq(MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY), anyString()))
        .thenReturn(_storePath);

    _bindingArgs = new FieldTable();
    AMQShortString argKey = AMQPFilterTypes.JMS_SELECTOR.getValue();
    String argValue = "some selector expression";
    _bindingArgs.put(argKey, argValue);

    reopenStore();
  }
Пример #5
0
 private Exchange createTestExchange() {
   Exchange exchange = mock(Exchange.class);
   when(exchange.getNameShortString()).thenReturn(AMQShortString.valueOf(getName()));
   when(exchange.getName()).thenReturn(getName());
   when(exchange.getTypeShortString()).thenReturn(AMQShortString.valueOf(getName() + "Type"));
   when(exchange.isAutoDelete()).thenReturn(true);
   when(exchange.getId()).thenReturn(_exchangeId);
   return exchange;
 }
Пример #6
0
  public void testBindQueue() throws Exception {
    AMQQueue queue = createTestQueue(QUEUE_NAME, "queueOwner", false);
    Binding binding =
        new Binding(
            UUIDGenerator.generateRandomUUID(),
            ROUTING_KEY,
            queue,
            _exchange,
            FieldTable.convertToMap(_bindingArgs));
    _store.bindQueue(binding);

    reopenStore();

    ByteBuffer argsAsBytes = ByteBuffer.wrap(_bindingArgs.getDataAsBytes());

    verify(_bindingRecoveryHandler)
        .binding(binding.getId(), _exchange.getId(), queue.getId(), ROUTING_KEY, argsAsBytes);
  }
Пример #7
0
 private Exchange createTestAlternateExchange() {
   UUID exchUuid = UUID.randomUUID();
   Exchange alternateExchange = mock(Exchange.class);
   when(alternateExchange.getId()).thenReturn(exchUuid);
   return alternateExchange;
 }
Пример #8
0
  public void methodReceived(AMQStateManager stateManager, ExchangeDeclareBody body, int channelId)
      throws AMQException {
    AMQProtocolSession session = stateManager.getProtocolSession();
    VirtualHost virtualHost = session.getVirtualHost();
    ExchangeRegistry exchangeRegistry = virtualHost.getExchangeRegistry();
    ExchangeFactory exchangeFactory = virtualHost.getExchangeFactory();
    final AMQChannel channel = session.getChannel(channelId);
    if (channel == null) {
      throw body.getChannelNotFoundException(channelId);
    }

    final AMQShortString exchangeName = body.getExchange();
    if (_logger.isDebugEnabled()) {
      _logger.debug(
          "Request to declare exchange of type " + body.getType() + " with name " + exchangeName);
    }

    synchronized (exchangeRegistry) {
      Exchange exchange = exchangeRegistry.getExchange(exchangeName);

      if (exchange == null) {
        if (body.getPassive() && ((body.getType() == null) || body.getType().length() == 0)) {
          throw body.getChannelException(
              AMQConstant.NOT_FOUND, "Unknown exchange: " + exchangeName);
        } else if (exchangeName.startsWith("amq.")) {
          throw body.getConnectionException(
              AMQConstant.NOT_ALLOWED,
              "Attempt to declare exchange: "
                  + exchangeName
                  + " which begins with reserved prefix 'amq.'.");
        } else if (exchangeName.startsWith("qpid.")) {
          throw body.getConnectionException(
              AMQConstant.NOT_ALLOWED,
              "Attempt to declare exchange: "
                  + exchangeName
                  + " which begins with reserved prefix 'qpid.'.");
        } else {
          try {
            exchange =
                exchangeFactory.createExchange(
                    exchangeName == null ? null : exchangeName.intern(),
                    body.getType() == null ? null : body.getType().intern(),
                    body.getDurable(),
                    body.getAutoDelete(),
                    body.getTicket());
            exchangeRegistry.registerExchange(exchange);

            if (exchange.isDurable()) {
              virtualHost.getMessageStore().createExchange(exchange);
            }
          } catch (AMQUnknownExchangeType e) {
            throw body.getConnectionException(
                AMQConstant.COMMAND_INVALID, "Unknown exchange: " + exchangeName, e);
          }
        }
      } else if (!exchange.getTypeShortString().equals(body.getType())
          && !((body.getType() == null || body.getType().length() == 0) && body.getPassive())) {

        throw new AMQConnectionException(
            AMQConstant.NOT_ALLOWED,
            "Attempt to redeclare exchange: "
                + exchangeName
                + " of type "
                + exchange.getTypeShortString()
                + " to "
                + body.getType()
                + ".",
            body.getClazz(),
            body.getMethod(),
            body.getMajor(),
            body.getMinor(),
            null);
      }
    }
    if (!body.getNowait()) {
      MethodRegistry methodRegistry = session.getMethodRegistry();
      AMQMethodBody responseBody = methodRegistry.createExchangeDeclareOkBody();
      channel.sync();
      session.writeFrame(responseBody.generateFrame(channelId));
    }
  }