@Override
    public void handle(Message<?> message) {
      ServerMessage msg =
          new ServerMessageImpl(
              storageManager.generateID(), VertxConstants.INITIAL_MESSAGE_BUFFER_SIZE);
      msg.setAddress(new SimpleString(queueName));
      msg.setDurable(true);
      msg.encodeMessageIDToBuffer();

      String replyAddress = message.replyAddress();
      if (replyAddress != null) {
        msg.putStringProperty(VertxConstants.VERTX_MESSAGE_REPLYADDRESS, replyAddress);
      }

      // it'd be better that Message expose its type information
      int type = getMessageType(message);

      msg.putIntProperty(VertxConstants.VERTX_MESSAGE_TYPE, type);

      manualEncodeVertxMessageBody(msg.getBodyBuffer(), message.body(), type);

      try {
        postOffice.route(msg, null, false);
      } catch (Exception e) {
        ActiveMQVertxLogger.LOGGER.error("failed to route msg " + msg, e);
      }
    }
  @Override
  public void serverSend(
      final Receiver receiver,
      final Delivery delivery,
      String address,
      int messageFormat,
      ByteBuf messageEncoded)
      throws Exception {
    EncodedMessage encodedMessage =
        new EncodedMessage(
            messageFormat,
            messageEncoded.array(),
            messageEncoded.arrayOffset(),
            messageEncoded.writerIndex());

    ServerMessage message = manager.getConverter().inbound(encodedMessage);
    // use the address on the receiver if not null, if null let's hope it was set correctly on the
    // message
    if (address != null) {
      message.setAddress(new SimpleString(address));
    }

    recoverContext();

    try {
      serverSession.send(message, false);

      manager
          .getServer()
          .getStorageManager()
          .afterCompleteOperations(
              new IOCallback() {
                @Override
                public void done() {
                  synchronized (connection.getLock()) {
                    delivery.settle();
                    connection.flush();
                  }
                }

                @Override
                public void onError(int errorCode, String errorMessage) {
                  synchronized (connection.getLock()) {
                    receiver.setCondition(
                        new ErrorCondition(
                            AmqpError.ILLEGAL_STATE, errorCode + ":" + errorMessage));
                    connection.flush();
                  }
                }
              });
    } finally {
      resetContext();
    }
  }
예제 #3
0
  @Test
  public void testAMQSize() throws Exception {
    message.setAddress(RandomUtil.randomSimpleString());

    int encodeSize = message.getEncodeSize();

    Filter moreThanSmall =
        FilterImpl.createFilter(new SimpleString("AMQSize > " + (encodeSize - 1)));
    Filter lessThanLarge =
        FilterImpl.createFilter(new SimpleString("AMQSize < " + (encodeSize + 1)));

    Filter lessThanSmall = FilterImpl.createFilter(new SimpleString("AMQSize < " + encodeSize));
    Filter moreThanLarge = FilterImpl.createFilter(new SimpleString("AMQSize > " + encodeSize));

    Assert.assertTrue(moreThanSmall.match(message));
    Assert.assertTrue(lessThanLarge.match(message));

    Assert.assertFalse(lessThanSmall.match(message));
    Assert.assertFalse(moreThanLarge.match(message));
  }