org.apache.qpid.proton.message.Message.encode()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中org.apache.qpid.proton.message.Message.encode()方法的一些代码示例,展示了Message.encode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.encode()方法的具体详情如下:
包路径:org.apache.qpid.proton.message.Message
类名称:Message
方法名:encode

Message.encode介绍

[英]Encodes the current Message contents into the given WritableBuffer instance.

This method attempts to encode all message data into the WritableBuffer and if the buffer has insufficient space it will throw an exception to indicate the buffer overflow condition. If successful the method returns the number of bytes written to the provided buffer to fully encode the message.
[中]将当前消息内容编码到给定的WritableBuffer实例中。
此方法尝试将所有消息数据编码到WritableBuffer中,如果缓冲区没有足够的空间,它将抛出异常以指示缓冲区溢出情况。如果成功,该方法将返回写入所提供缓冲区的字节数,以对消息进行完全编码。

代码示例

代码示例来源:origin: Azure/azure-service-bus-java

static int encodeMessageToCustomArray(Message message, byte[] encodedBytes, int offset, int length) throws PayloadSizeExceededException
{
  try
  {
    return message.encode(encodedBytes, offset, length);
  }
  catch(BufferOverflowException exception)
  {
    throw new PayloadSizeExceededException(String.format("Size of the payload exceeded Maximum message size: %s KB", length / 1024), exception);		
  }
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-amqp

private void encode(Message value, OutputStream outStream, int messageSize)
  throws IOException, BufferOverflowException {
 byte[] data = new byte[messageSize];
 int bytesWritten = value.encode(data, 0, data.length);
 VarInt.encode(bytesWritten, outStream);
 outStream.write(data, 0, bytesWritten);
}

代码示例来源:origin: org.apache.qpid/qpid-jms-client

/**
   * Given a Message instance, encode the Message to the wire level representation
   * of that Message.
   *
   * @param message
   *      the Message that is to be encoded into the wire level representation.
   *
   * @return a buffer containing the wire level representation of the input Message.
   */
  public static ReadableBuffer encodeMessage(Message message) {
    final int BUFFER_SIZE = 4096;
    byte[] encodedMessage = new byte[BUFFER_SIZE];
    int encodedSize = 0;
    while (true) {
      try {
        encodedSize = message.encode(encodedMessage, 0, encodedMessage.length);
        break;
      } catch (java.nio.BufferOverflowException e) {
        encodedMessage = new byte[encodedMessage.length * 2];
      }
    }

    return ReadableBuffer.ByteBufferReader.wrap(ByteBuffer.wrap(encodedMessage, 0, encodedSize));
  }
}

代码示例来源:origin: apache/qpid-jms

/**
   * Given a Message instance, encode the Message to the wire level representation
   * of that Message.
   *
   * @param message
   *      the Message that is to be encoded into the wire level representation.
   *
   * @return a buffer containing the wire level representation of the input Message.
   */
  public static ReadableBuffer encodeMessage(Message message) {
    final int BUFFER_SIZE = 4096;
    byte[] encodedMessage = new byte[BUFFER_SIZE];
    int encodedSize = 0;
    while (true) {
      try {
        encodedSize = message.encode(encodedMessage, 0, encodedMessage.length);
        break;
      } catch (java.nio.BufferOverflowException e) {
        encodedMessage = new byte[encodedMessage.length * 2];
      }
    }

    return ReadableBuffer.ByteBufferReader.wrap(ByteBuffer.wrap(encodedMessage, 0, encodedSize));
  }
}

代码示例来源:origin: org.apache.qpid/proton-hawtdispatch

static Buffer encode(Message message, int sizeHint) {
  byte[] buffer = new byte[sizeHint];
  int size = ((ProtonJMessage)message).encode2(buffer, 0, sizeHint);
  if( size > sizeHint ) {
    buffer = new byte[size];
    size = message.encode(buffer, 0, size);
  }
  return new Buffer(buffer, 0, size);
}

代码示例来源:origin: Azure/azure-event-hubs-java

public CompletableFuture<Void> send(Message msg) {
  int payloadSize = AmqpUtil.getDataSerializedSize(msg);
  final int maxMessageSizeTemp = this.maxMessageSize;
  int allocationSize = Math.min(payloadSize + ClientConstants.MAX_EVENTHUB_AMQP_HEADER_SIZE_BYTES, maxMessageSizeTemp);
  final byte[] bytes = new byte[allocationSize];
  int encodedSize = 0;
  try {
    encodedSize = msg.encode(bytes, 0, allocationSize);
  } catch (BufferOverflowException exception) {
    final CompletableFuture<Void> sendTask = new CompletableFuture<Void>();
    sendTask.completeExceptionally(new PayloadSizeExceededException(String.format(Locale.US,
        "Entity(%s): size of the payload exceeded Maximum message size: %s kb",
        this.sendPath, maxMessageSizeTemp / 1024), exception));
    return sendTask;
  }
  return this.send(bytes, encodedSize, DeliveryImpl.DEFAULT_MESSAGE_FORMAT);
}

代码示例来源:origin: apache/activemq-artemis

private void encodeAndSend(Message message, Delivery delivery) throws IOException {
 int encodedSize;
 while (true) {
   try {
    encodedSize = message.encode(encodeBuffer, 0, encodeBuffer.length);
    break;
   } catch (java.nio.BufferOverflowException e) {
    encodeBuffer = new byte[encodeBuffer.length * 2];
   }
 }
 int sentSoFar = 0;
 while (true) {
   int sent = getEndpoint().send(encodeBuffer, sentSoFar, encodedSize - sentSoFar);
   if (sent > 0) {
    sentSoFar += sent;
    if ((encodedSize - sentSoFar) == 0) {
      break;
    }
   } else {
    LOG.warn("{} failed to send any data from current Message.", this);
   }
 }
}

代码示例来源:origin: Azure/azure-iot-sdk-java

length = message.encode(msgData, 0, msgData.length);
break;

代码示例来源:origin: apache/activemq-artemis

private void sendTxCommand(Message message) throws IOException {
 int encodedSize = 0;
 byte[] buffer = OUTBOUND_BUFFER;
 while (true) {
   try {
    encodedSize = message.encode(buffer, 0, buffer.length);
    break;
   } catch (BufferOverflowException e) {
    buffer = new byte[buffer.length * 2];
   }
 }
 Sender sender = getEndpoint();
 sender.send(buffer, 0, encodedSize);
 sender.advance();
}

代码示例来源:origin: Azure/azure-event-hubs-java

private int getSize(final EventDataImpl eventData, final boolean isFirst) {

    final Message amqpMessage = this.partitionKey != null ? eventData.toAmqpMessage(this.partitionKey) : eventData.toAmqpMessage();
    int eventSize = amqpMessage.encode(this.eventBytes, 0, maxMessageSize); // actual encoded bytes size
    eventSize += 16; // data section overhead

    if (isFirst) {
      amqpMessage.setBody(null);
      amqpMessage.setApplicationProperties(null);
      amqpMessage.setProperties(null);
      amqpMessage.setDeliveryAnnotations(null);

      eventSize += amqpMessage.encode(this.eventBytes, 0, maxMessageSize);
    }

    return eventSize;
  }
}

代码示例来源:origin: com.microsoft.azure.iothub-java-client/iothub-java-device-client

length = message.encode(msgData, 0, msgData.length);
break;

代码示例来源:origin: org.apache.qpid/qpid-jms-client

private void sendTxCommand(Message message) throws IOException {
    int encodedSize = 0;
    byte[] buffer = OUTBOUND_BUFFER;
    while (true) {
      try {
        encodedSize = message.encode(buffer, 0, buffer.length);
        break;
      } catch (BufferOverflowException e) {
        buffer = new byte[buffer.length * 2];
      }
    }

    Sender sender = getEndpoint();
    sender.send(buffer, 0, encodedSize);
    sender.advance();
  }
}

代码示例来源:origin: apache/qpid-jms

private void sendTxCommand(Message message) throws IOException {
    int encodedSize = 0;
    byte[] buffer = OUTBOUND_BUFFER;
    while (true) {
      try {
        encodedSize = message.encode(buffer, 0, buffer.length);
        break;
      } catch (BufferOverflowException e) {
        buffer = new byte[buffer.length * 2];
      }
    }

    Sender sender = getEndpoint();
    sender.send(buffer, 0, encodedSize);
    sender.advance();
  }
}

代码示例来源:origin: Azure/azure-event-hubs-java

public void request(
    final Message message,
    final OperationResult<Message, Exception> onResponse) {
  if (message == null)
    throw new IllegalArgumentException("message cannot be null");
  if (message.getMessageId() != null)
    throw new IllegalArgumentException("message.getMessageId() should be null");
  if (message.getReplyTo() != null)
    throw new IllegalArgumentException("message.getReplyTo() should be null");
  message.setMessageId("request" + UnsignedLong.valueOf(this.requestId.incrementAndGet()).toString());
  message.setReplyTo(this.replyTo);
  this.inflightRequests.put(message.getMessageId(), onResponse);
  sendLink.delivery(UUID.randomUUID().toString().replace("-", StringUtil.EMPTY).getBytes());
  final int payloadSize = AmqpUtil.getDataSerializedSize(message) + 512; // need buffer for headers
  final byte[] bytes = new byte[payloadSize];
  final int encodedSize = message.encode(bytes, 0, payloadSize);
  receiveLink.flow(1);
  sendLink.send(bytes, 0, encodedSize);
  sendLink.advance();
}

代码示例来源:origin: Azure/azure-iot-sdk-java

length = protonMessage.encode(msgData, 0, msgData.length);
  break;
} catch (BufferOverflowException e)

代码示例来源:origin: strimzi/strimzi-kafka-bridge

message.getAddress().replace('/', '.');
int encoded = message.encode(buffer, 0, AmqpRawMessageConverter.BUFFER_SIZE);
value = Arrays.copyOfRange(buffer, 0, encoded);

代码示例来源:origin: Azure/azure-event-hubs-java

int encodedSize = batchMessage.encode(bytes, 0, maxMessageSizeTemp);
int byteArrayOffset = encodedSize;
  int messageSizeBytes = amqpMessage.encode(messageBytes, 0, allocationSize);
  messageWrappedByData.setBody(new Data(new Binary(messageBytes, 0, messageSizeBytes)));
    encodedSize = messageWrappedByData.encode(bytes, byteArrayOffset, maxMessageSizeTemp - byteArrayOffset - 1);
  } catch (BufferOverflowException exception) {
    final CompletableFuture<Void> sendTask = new CompletableFuture<>();

代码示例来源:origin: org.apache.qpid/proton

encoded = m.encode(_buffer, 0, _buffer.length);
  break;
} catch (java.nio.BufferOverflowException e) {

代码示例来源:origin: com.microsoft.azure.iot/proton-j-azure-iot

encoded = m.encode(buffer, 0, buffer.length);
  break;
} catch (java.nio.BufferOverflowException e) {

代码示例来源:origin: org.apache.qpid/proton-j-impl

encoded = m.encode(buffer, 0, buffer.length);
  break;
} catch (java.nio.BufferOverflowException e) {

相关文章