本文整理了Java中org.apache.qpid.proton.amqp.Binary
类的一些代码示例,展示了Binary
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Binary
类的具体详情如下:
包路径:org.apache.qpid.proton.amqp.Binary
类名称:Binary
暂无
代码示例来源:origin: org.eclipse.hono/hono-core
/**
* Set the payload of the message using a {@link Data} section.
* <p>
* If the payload is {@code null}, then neither the payload, nor content type will be set.
* </p>
*
* @param message The message to update.
* @param contentType An optional content type.
* @param payload The optional message payload.
*
* @throws NullPointerException If the parameter {@code message} was {@code null}.
*/
public static void setPayload(final Message message, final String contentType, final byte[] payload) {
Objects.requireNonNull(message);
if (contentType != null) {
message.setContentType(contentType);
}
if (payload != null) {
message.setBody(new Data(new Binary(payload)));
}
}
代码示例来源:origin: apache/qpid-jms
@Override
public byte[] getUserIdBytes() {
if(properties == null || properties.getUserId() == null) {
return null;
} else {
final Binary userId = properties.getUserId();
byte[] id = new byte[userId.getLength()];
System.arraycopy(userId.getArray(), userId.getArrayOffset(), id, 0, userId.getLength());
return id;
}
}
代码示例来源:origin: Azure/azure-iot-sdk-java
/**
* Returns the amqp body used in the message
* @return Byte array
*/
public byte[] getAmqpBody()
{
Data msgData = (Data)this.messageImpl.getBody();
Binary binData = msgData.getValue();
byte[] msgBody = new byte[binData.getLength()];
ByteBuffer buffer = binData.asByteBuffer();
buffer.get(msgBody);
return msgBody;
}
代码示例来源:origin: org.apache.qpid/proton-j
BinaryElement(Element parent, Element prev, Binary b)
{
super(parent, prev);
byte[] data = new byte[b.getLength()];
System.arraycopy(b.getArray(),b.getArrayOffset(),data,0,b.getLength());
_value = new Binary(data);
}
代码示例来源:origin: org.apache.qpid/qpid-jms-client
@Override
public Object get(String key) {
Object value = messageBodyMap.get(key);
if (value instanceof Binary) {
// Copy to a byte[], ensure we copy only the required portion.
Binary bin = ((Binary) value);
value = Arrays.copyOfRange(bin.getArray(), bin.getArrayOffset(), bin.getLength());
}
return value;
}
代码示例来源:origin: org.apache.activemq/activemq-all
@SuppressWarnings("unchecked")
protected void populateMessage(ActiveMQMessage jms, org.apache.qpid.proton.message.Message amqp) throws Exception {
Header header = amqp.getHeader();
if (header != null) {
jms.setBooleanProperty(JMS_AMQP_HEADER, true);
final ApplicationProperties ap = amqp.getApplicationProperties();
if (ap != null) {
for (Map.Entry<String, Object> entry : ((Map<String, Object>) ap.getValue()).entrySet()) {
if (properties != null) {
jms.setBooleanProperty(JMS_AMQP_PROPERTIES, true);
if (properties.getMessageId() != null) {
jms.setJMSMessageID(AMQPMessageIdHelper.INSTANCE.toBaseMessageIdString(properties.getMessageId()));
Binary userId = properties.getUserId();
if (userId != null) {
jms.setUserID(new String(userId.getArray(), userId.getArrayOffset(), userId.getLength(), StandardCharsets.UTF_8));
if (properties.getTo() != null) {
if (properties.getContentType() != null) {
jms.setStringProperty(JMS_AMQP_CONTENT_TYPE, properties.getContentType().toString());
if (properties.getContentEncoding() != null) {
jms.setStringProperty(JMS_AMQP_CONTENT_ENCODING, properties.getContentEncoding().toString());
if (properties.getCreationTime() != null) {
代码示例来源:origin: EnMasseProject/enmasse
/**
* Return a raw AMQP message
*
* @return
*/
public Message toAmqp() {
Message message = ProtonHelper.message();
message.setMessageId(this.messageId);
Map<Symbol, Object> map = new HashMap<>();
map.put(Symbol.valueOf(AMQP_RETAIN_ANNOTATION), this.isRetain);
map.put(Symbol.valueOf(AMQP_QOS_ANNOTATION), this.qos.value());
MessageAnnotations messageAnnotations = new MessageAnnotations(map);
message.setMessageAnnotations(messageAnnotations);
message.setAddress(this.topic);
Header header = new Header();
header.setDurable(this.qos != MqttQoS.AT_MOST_ONCE);
message.setHeader(header);
message.setDeliveryCount(this.isDup ? 1 : 0);
// the payload could be null (or empty)
if (this.payload != null)
message.setBody(new Data(new Binary(this.payload.getBytes())));
return message;
}
代码示例来源:origin: apache/activemq-artemis
private static ServerJMSMessage processProperties(ServerJMSMessage jms, Properties properties) throws Exception {
if (properties != null) {
if (properties.getMessageId() != null) {
jms.setJMSMessageID(AMQPMessageIdHelper.INSTANCE.toMessageIdString(properties.getMessageId()));
Binary userId = properties.getUserId();
if (userId != null) {
jms.setStringProperty("JMSXUserID", new String(userId.getArray(), userId.getArrayOffset(), userId.getLength(), StandardCharsets.UTF_8));
if (properties.getTo() != null) {
if (properties.getContentType() != null) {
jms.setStringProperty(JMS_AMQP_CONTENT_TYPE, properties.getContentType().toString());
if (properties.getContentEncoding() != null) {
jms.setStringProperty(JMS_AMQP_CONTENT_ENCODING, properties.getContentEncoding().toString());
if (properties.getCreationTime() != null) {
代码示例来源:origin: apache/activemq-artemis
final Properties properties = new Properties();
Map<Symbol, Object> daMap = null;
final Map<Symbol, Object> maMap = new HashMap<>();
properties.setSubject(type);
properties.setMessageId(AMQPMessageIdHelper.INSTANCE.toIdObject(messageId));
} catch (ActiveMQAMQPIllegalStateException e) {
properties.setMessageId(messageId);
String value = message.getStringProperty(key);
if (value != null) {
properties.setUserId(Binary.create(StandardCharsets.UTF_8.encode(value)));
objectProperty = new Binary((byte[]) objectProperty);
encoder.writeObject(new DeliveryAnnotations(daMap));
encoder.writeObject(new MessageAnnotations(maMap));
encoder.writeObject(properties);
if (apMap != null) {
代码示例来源:origin: EnMasseProject/enmasse
MqttQoS qos = MqttQoS.AT_MOST_ONCE;
String topic = message.getAddress();
MessageAnnotations messageAnnotations = message.getMessageAnnotations();
if (messageAnnotations == null) {
if (message.getHeader() != null) {
qos = ((message.getHeader().getDurable() == null) || !message.getHeader().getDurable())
if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQ_ORIG_ADDRESS_ANNOTATION))) {
topic = (String) messageAnnotations.getValue().get(Symbol.valueOf(AMQ_ORIG_ADDRESS_ANNOTATION));
if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQP_RETAIN_ANNOTATION))) {
isRetain = (boolean) messageAnnotations.getValue().get(Symbol.valueOf(AMQP_RETAIN_ANNOTATION));
if ((section != null) && (section instanceof Data)) {
Buffer payload = Buffer.buffer(((Data) section).getValue().getArray());
return new AmqpPublishMessage(message.getMessageId(), qos, isDup, isRetain, topic, payload);
代码示例来源:origin: Azure/azure-service-bus-java
amqpMessage.setBody(new AmqpValue(body.getValueData()));
amqpMessage.setBody(new AmqpSequence(Utils.getSequenceFromMessageBody(body)));
amqpMessage.setBody(new Data(new Binary(Utils.getDataFromMessageBody(body))));
amqpMessage.setCorrelationId(brokeredMessage.getCorrelationId());
amqpMessage.setSubject(brokeredMessage.getLabel());
amqpMessage.getProperties().setTo(brokeredMessage.getTo());
amqpMessage.setReplyTo(brokeredMessage.getReplyTo());
amqpMessage.setReplyToGroupId(brokeredMessage.getReplyToSessionId());
if(brokeredMessage.getScheduledEnqueueTimeUtc() != null)
messageAnnotationsMap.put(Symbol.valueOf(ClientConstants.SCHEDULEDENQUEUETIMENAME), Date.from(brokeredMessage.getScheduledEnqueueTimeUtc()));
messageAnnotationsMap.put(Symbol.valueOf(ClientConstants.PARTITIONKEYNAME), brokeredMessage.getPartitionKey());
messageAnnotationsMap.put(Symbol.valueOf(ClientConstants.VIAPARTITIONKEYNAME), brokeredMessage.getViaPartitionKey());
amqpMessage.setMessageAnnotations(new MessageAnnotations(messageAnnotationsMap));
代码示例来源:origin: strimzi/strimzi-kafka-bridge
message.setAddress(address);
message.setMessageId(entry.getValue());
} else if (entry.getKey().equals(AmqpJsonMessageConverter.TO)) {
message.setAddress(entry.getValue().toString());
} else if (entry.getKey().equals(AmqpJsonMessageConverter.SUBJECT)) {
message.setSubject(entry.getValue().toString());
messageAnnotationsMap.put(Symbol.valueOf(AmqpBridge.AMQP_PARTITION_ANNOTATION), record.partition());
messageAnnotationsMap.put(Symbol.valueOf(AmqpBridge.AMQP_OFFSET_ANNOTATION), record.offset());
messageAnnotationsMap.put(Symbol.valueOf(AmqpBridge.AMQP_KEY_ANNOTATION), record.key());
messageAnnotationsMap.put(Symbol.valueOf(AmqpBridge.AMQP_TOPIC_ANNOTATION), record.topic());
MessageAnnotations messageAnnotations = new MessageAnnotations(messageAnnotationsMap);
message.setMessageAnnotations(messageAnnotations);
message.setBody(new Data(new Binary(Base64.getDecoder().decode(value))));
代码示例来源:origin: EnMasseProject/enmasse
if (!message.getSubject().equals(AMQP_SUBJECT)) {
throw new IllegalArgumentException(String.format("AMQP message subject is no %s", AMQP_SUBJECT));
MessageAnnotations messageAnnotations = message.getMessageAnnotations();
if (messageAnnotations == null) {
throw new IllegalArgumentException("AMQP message has no annotations");
if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQP_RETAIN_ANNOTATION))) {
isRetain = (boolean) messageAnnotations.getValue().get(Symbol.valueOf(AMQP_RETAIN_ANNOTATION));
if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQP_QOS_ANNOTATION))) {
int value = (int) messageAnnotations.getValue().get(Symbol.valueOf(AMQP_QOS_ANNOTATION));
qos = MqttQoS.valueOf(value);
} else {
if (message.getHeader() != null) {
qos = ((message.getHeader().getDurable() == null) || !message.getHeader().getDurable())
if ((section != null) && (section instanceof Data)) {
Buffer payload = Buffer.buffer(((Data) section).getValue().getArray());
return new AmqpWillMessage(isRetain, topic, qos, payload);
代码示例来源:origin: Azure/azure-iot-sdk-java
if (d != null)
Binary b = d.getValue();
msgBody = new byte[b.getLength()];
ByteBuffer buffer = b.asByteBuffer();
buffer.get(msgBody);
if (properties != null)
if (properties.getCorrelationId() != null)
iotHubTransportMessage.setCorrelationId(properties.getCorrelationId().toString());
if (properties.getMessageId() != null)
iotHubTransportMessage.setMessageId(properties.getMessageId().toString());
if (properties.getUserId() != null)
iotHubTransportMessage.setProperty(AMQPS_APP_PROPERTY_PREFIX + USER_ID_KEY, properties.getUserId().toString());
if (properties.getContentEncoding() != null)
iotHubTransportMessage.setContentEncoding(properties.getContentEncoding().toString());
if (properties.getContentType() != null)
iotHubTransportMessage.setContentType(properties.getContentType().toString());
代码示例来源:origin: strimzi/strimzi-kafka-bridge
@Override
public Message toMessage(String address, KafkaConsumerRecord<String, byte[]> record) {
Message message = Proton.message();
message.setAddress(address);
// put message annotations about partition, offset and key (if not null)
Map<Symbol, Object> map = new HashMap<>();
map.put(Symbol.valueOf(AmqpBridge.AMQP_PARTITION_ANNOTATION), record.partition());
map.put(Symbol.valueOf(AmqpBridge.AMQP_OFFSET_ANNOTATION), record.offset());
map.put(Symbol.valueOf(AmqpBridge.AMQP_KEY_ANNOTATION), record.key());
map.put(Symbol.valueOf(AmqpBridge.AMQP_TOPIC_ANNOTATION), record.topic());
MessageAnnotations messageAnnotations = new MessageAnnotations(map);
message.setMessageAnnotations(messageAnnotations);
message.setBody(new Data(new Binary(record.value())));
return message;
}
代码示例来源:origin: strimzi/strimzi-kafka-bridge
String topic = (message.getAddress() == null) ?
kafkaTopic :
message.getAddress().replace('/', '.');
Section body = message.getBody();
Binary binary = ((Data)body).getValue();
value = binary.getArray();
partition = messageAnnotations.getValue().get(Symbol.getSymbol(AmqpBridge.AMQP_PARTITION_ANNOTATION));
key = messageAnnotations.getValue().get(Symbol.getSymbol(AmqpBridge.AMQP_KEY_ANNOTATION));
代码示例来源:origin: org.apache.qpid/proton-hawtdispatch
public Message createBinaryMessage(byte value[], int offset, int len) {
Message msg = Message.Factory.create();
Data body = new Data(new Binary(value, offset,len));
msg.setBody(body);
return msg;
}
}
代码示例来源:origin: Azure/azure-service-bus-java
messageEntry.put(ClientConstants.REQUEST_RESPONSE_MESSAGE, new Binary(encodedPair.getFirstItem(), 0, encodedPair.getSecondItem()));
messageEntry.put(ClientConstants.REQUEST_RESPONSE_MESSAGE_ID, message.getMessageId());
String sessionId = message.getGroupId();
if(!StringUtil.isNullOrEmpty(sessionId))
Object partitionKey = message.getMessageAnnotations().getValue().get(Symbol.valueOf(ClientConstants.PARTITIONKEYNAME));
if(partitionKey != null && !((String)partitionKey).isEmpty())
Object viaPartitionKey = message.getMessageAnnotations().getValue().get(Symbol.valueOf(ClientConstants.VIAPARTITIONKEYNAME));
if(viaPartitionKey != null && !((String)viaPartitionKey).isEmpty())
代码示例来源:origin: io.vertx/vertx-amqp-bridge
@Test
public void testJSON_to_AMQP_VerifyDataBody() {
String testContent = "myTestContent";
JsonObject jsonObject = new JsonObject();
jsonObject.put(AmqpConstants.BODY, testContent.getBytes(StandardCharsets.UTF_8));
jsonObject.put(AmqpConstants.BODY_TYPE, AmqpConstants.BODY_TYPE_DATA);
Message protonMsg = translator.convertToAmqpMessage(jsonObject);
assertNotNull("Expected converted msg", protonMsg);
Section body = protonMsg.getBody();
assertTrue("Unexpected body type", body instanceof Data);
assertNotNull("Unexpected body content", body);
assertEquals("Unexpected message body value", new Binary(testContent.getBytes(StandardCharsets.UTF_8)),
((Data) body).getValue());
}
代码示例来源:origin: org.apache.qpid/proton
public void plain(String username, String password)
{
client();
_chosenMechanism = Symbol.valueOf("PLAIN");
byte[] usernameBytes = username.getBytes();
byte[] passwordBytes = password.getBytes();
byte[] data = new byte[usernameBytes.length+passwordBytes.length+2];
System.arraycopy(usernameBytes, 0, data, 1, usernameBytes.length);
System.arraycopy(passwordBytes, 0, data, 2+usernameBytes.length, passwordBytes.length);
setChallengeResponse(new Binary(data));
}
内容来源于网络,如有侵权,请联系作者删除!