本文整理汇总了Java中org.apache.qpid.proton.amqp.messaging.AmqpValue类的典型用法代码示例。如果您正苦于以下问题:Java AmqpValue类的具体用法?Java AmqpValue怎么用?Java AmqpValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AmqpValue类属于org.apache.qpid.proton.amqp.messaging包,在下文中一共展示了AmqpValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAndSendRequest
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
/**
* Creates a request message for a payload and headers and sends it to the peer.
*
* @param action The operation that the request is supposed to trigger/invoke.
* @param properties The headers to include in the request message as AMQP application properties.
* @param payload The payload to include in the request message as a an AMQP Value section.
* @param resultHandler The handler to notify about the outcome of the request. The handler is failed with
* a {@link ServerErrorException} if the request cannot be sent to the remote service,
* e.g. because there is no connection to the service or there are no credits available
* for sending the request or the request timed out.
* @throws NullPointerException if action or result handler are {@code null}.
* @throws IllegalArgumentException if the properties contain any non-primitive typed values.
* @see AbstractHonoClient#setApplicationProperties(Message, Map)
*/
protected final void createAndSendRequest(final String action, final Map<String, Object> properties, final JsonObject payload,
final Handler<AsyncResult<R>> resultHandler) {
Objects.requireNonNull(action);
Objects.requireNonNull(resultHandler);
if (isOpen()) {
final Message request = createMessage(action, properties);
if (payload != null) {
request.setContentType(RequestResponseApiConstants.CONTENT_TYPE_APPLICATION_JSON);
request.setBody(new AmqpValue(payload.encode()));
}
sendRequest(request, resultHandler);
} else {
resultHandler.handle(Future.failedFuture(new ServerErrorException(
HttpURLConnection.HTTP_UNAVAILABLE, "sender and/or receiver link is not open")));
}
}
示例2: receiverHandler
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
private void receiverHandler(ProtonReceiver receiver, ProtonDelivery delivery, Message message) {
Section section = message.getBody();
byte[] data = null;
if (section instanceof AmqpValue) {
data = ((String) ((AmqpValue)section).getValue()).getBytes();
} else if (section instanceof Data) {
data = ((Data)message.getBody()).getValue().getArray();
} else {
log.error("Discarded message : body type not supported");
}
MessageDelivery messageDelivery =
new MessageDelivery(receiver.getSource().getAddress(), data);
delivery.disposition(Accepted.getInstance(), true);
this.receivedHandler.handle(messageDelivery);
}
示例3: handleMessage
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
private void handleMessage(final String endpoint, final Message msg) {
final String deviceId = MessageHelper.getDeviceId(msg);
final Section body = msg.getBody();
String content = null;
if (body instanceof Data) {
content = ((Data) msg.getBody()).getValue().toString();
} else if (body instanceof AmqpValue) {
content = ((AmqpValue) msg.getBody()).getValue().toString();
}
LOG.info("received {} message [device: {}, content-type: {}]: {}", endpoint, deviceId, msg.getContentType(), content);
if (msg.getApplicationProperties() != null) {
LOG.info("... with application properties: {}", msg.getApplicationProperties().getValue());
}
}
示例4: testCreateAndSendRequestSendsProperRequestMessage
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
/**
* Verifies that the client creates and sends a message based on provided headers and payload
* and sets a timer for canceling the request if no response is received.
*
* @param ctx The vert.x test context.
*/
@SuppressWarnings("unchecked")
@Test
public void testCreateAndSendRequestSendsProperRequestMessage(final TestContext ctx) {
// GIVEN a request-response client that times out requests after 200 ms
client.setRequestTimeout(200);
// WHEN sending a request message with some headers and payload
final JsonObject payload = new JsonObject().put("key", "value");
final Map<String, Object> props = Collections.singletonMap("test-key", "test-value");
client.createAndSendRequest("get", props, payload, s -> {});
// THEN the message is sent and the message being sent contains the headers as application properties
ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
verify(sender).send(messageCaptor.capture());
assertThat(messageCaptor.getValue(), is(notNullValue()));
assertThat(messageCaptor.getValue().getBody(), is(notNullValue()));
assertThat(messageCaptor.getValue().getBody(), instanceOf(AmqpValue.class));
AmqpValue body = (AmqpValue) messageCaptor.getValue().getBody();
assertThat(body.getValue(), is(payload.encode()));
assertThat(messageCaptor.getValue().getApplicationProperties(), is(notNullValue()));
assertThat(messageCaptor.getValue().getApplicationProperties().getValue().get("test-key"), is("test-value"));
// and a timer has been set to time out the request after 200 ms
verify(vertx).setTimer(eq(200L), any(Handler.class));
}
示例5: verify
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
/**
* Checks whether a given registration message contains all required properties.
*
* @param linkTarget The resource path to check the message's properties against for consistency.
* @param msg The AMQP 1.0 message to perform the checks on.
* @return {@code true} if the message passes all checks.
*/
public static boolean verify(final ResourceIdentifier linkTarget, final Message msg) {
if (!verifyStandardProperties(linkTarget, msg)) {
return false;
} else if (msg.getMessageId() == null && msg.getCorrelationId() == null) {
LOG.trace("message has neither a message-id nor correlation-id");
return false;
} else if (!RegistrationConstants.isValidAction(msg.getSubject())) {
LOG.trace("message [{}] does not contain valid action property", msg.getMessageId());
return false;
} else if (msg.getReplyTo() == null) {
LOG.trace("message [{}] contains no reply-to address", msg.getMessageId());
return false;
} else if (msg.getBody() != null) {
if (!(msg.getBody() instanceof AmqpValue)) {
LOG.trace("message [{}] contains non-AmqpValue section payload", msg.getMessageId());
return false;
} else {
return true;
}
} else {
return true;
}
}
示例6: testProcessMessageSendsRequestViaEventBus
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
/**
* Verifies that the endpoint forwards a request message via the event bus.
*/
@SuppressWarnings("unchecked")
@Test
public void testProcessMessageSendsRequestViaEventBus() {
Message msg = ProtonHelper.message();
msg.setSubject(CredentialsConstants.OPERATION_GET);
MessageHelper.addDeviceId(msg, "4711");
MessageHelper.addTenantId(msg, Constants.DEFAULT_TENANT);
MessageHelper.annotate(msg, resource);
msg.setBody(new AmqpValue(new JsonObject().put("temp", 15).encode()));
endpoint.processRequest(msg, resource, Constants.PRINCIPAL_ANONYMOUS);
verify(eventBus).send(contains(CredentialsConstants.EVENT_BUS_ADDRESS_CREDENTIALS_IN), any(JsonObject.class), any(Handler.class));
}
示例7: testRead
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
@Test
public void testRead() throws Exception {
PCollection<Message> output = pipeline.apply(AmqpIO.read()
.withMaxNumRecords(100)
.withAddresses(Collections.singletonList(broker.getQueueUri("testRead"))));
PAssert.thatSingleton(output.apply(Count.<Message>globally())).isEqualTo(100L);
Messenger sender = Messenger.Factory.create();
sender.start();
for (int i = 0; i < 100; i++) {
Message message = Message.Factory.create();
message.setAddress(broker.getQueueUri("testRead"));
message.setBody(new AmqpValue("Test " + i));
sender.put(message);
sender.send();
}
sender.stop();
pipeline.run();
}
示例8: sendMessage
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
public void sendMessage(String messageBody, long timeout, TimeUnit timeUnit) throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
protonClient.connect("127.0.0.1", protonServer.actualPort(), event -> {
ProtonConnection connection = event.result().open();
Target target = new Target();
target.setAddress(address);
target.setCapabilities(Symbol.getSymbol("topic"));
ProtonSender sender = connection.createSender(address);
sender.setTarget(target);
sender.open();
Message message = Message.Factory.create();
message.setBody(new AmqpValue(messageBody));
message.setAddress(address);
sender.send(message, delivery -> latch.countDown());
});
latch.await(timeout, timeUnit);
}
示例9: recvMessages
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
public CompletableFuture<List<String>> recvMessages(long numMessages, long attachTimeout, TimeUnit timeUnit) throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
CompletableFuture<List<String>> future = new CompletableFuture<>();
List<String> messages = new ArrayList<>();
protonClient.connect("localhost", protonServer.actualPort(), event -> {
ProtonConnection connection = event.result().open();
Source source = new Source();
source.setAddress(address);
source.setCapabilities(Symbol.getSymbol("topic"));
connection.createReceiver(address)
.openHandler(opened -> latch.countDown())
.setSource(source)
.handler((delivery, message) -> {
messages.add((String) ((AmqpValue) message.getBody()).getValue());
if (messages.size() == numMessages) {
future.complete(new ArrayList<>(messages));
}
})
.open();
});
latch.await(attachTimeout, timeUnit);
return future;
}
示例10: checkRouter
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
private List<String> checkRouter(SyncRequestClient client, String entityType, String attributeName) {
Map<String, String> properties = new LinkedHashMap<>();
properties.put("operation", "QUERY");
properties.put("entityType", entityType);
Map body = new LinkedHashMap<>();
body.put("attributeNames", Arrays.asList(attributeName));
Message message = Proton.message();
message.setAddress("$management");
message.setApplicationProperties(new ApplicationProperties(properties));
message.setBody(new AmqpValue(body));
try {
Message response = client.request(message, 10, TimeUnit.SECONDS);
AmqpValue value = (AmqpValue) response.getBody();
Map values = (Map) value.getValue();
List<List<String>> results = (List<List<String>>) values.get("results");
return results.stream().map(l -> l.get(0)).collect(Collectors.toList());
} catch (Exception e) {
log.info("Error requesting router status. Ignoring", e);
eventLogger.log(RouterCheckFailed, e.getMessage(), Warning, AddressSpace, addressSpaceName);
return Collections.emptyList();
}
}
示例11: getSubscriberCount
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
@Override
public int getSubscriberCount(AmqpClient queueClient, Destination replyQueue, String queue) throws Exception {
Message requestMessage = Message.Factory.create();
Map<String, String> appProperties = new HashMap<>();
appProperties.put(resourceProperty, "queue." + queue);
appProperties.put(operationProperty, "getConsumerCount");
requestMessage.setAddress(managementAddress);
requestMessage.setApplicationProperties(new ApplicationProperties(appProperties));
requestMessage.setReplyTo(replyQueue.getAddress());
requestMessage.setBody(new AmqpValue("[]"));
Future<Integer> sent = queueClient.sendMessages(managementAddress, requestMessage);
assertThat(sent.get(30, TimeUnit.SECONDS), is(1));
Logging.log.info("request sent");
Future<List<Message>> received = queueClient.recvMessages(replyQueue.getAddress(), 1);
assertThat(received.get(30, TimeUnit.SECONDS).size(), is(1));
AmqpValue val = (AmqpValue) received.get().get(0).getBody();
Logging.log.info("answer received: " + val.toString());
String count = val.getValue().toString().replaceAll("\\[|]|\"", "");
return Integer.valueOf(count);
}
示例12: from
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
/**
* Return an AMQP_UNSUBSCRIBE message from the raw AMQP one
*
* @param message raw AMQP message
* @return AMQP_UNSUBSCRIBE message
*/
@SuppressWarnings("unchecked")
public static AmqpUnsubscribeMessage from(Message message) {
if (!message.getSubject().equals(AMQP_SUBJECT)) {
throw new IllegalArgumentException(String.format("AMQP message subject is no s%", AMQP_SUBJECT));
}
Section section = message.getBody();
if ((section != null) && (section instanceof AmqpValue)) {
List<String> topics = (List<String>) ((AmqpValue) section).getValue();
return new AmqpUnsubscribeMessage(AmqpHelper.getClientIdFromPublishAddress((String) message.getCorrelationId()),
message.getMessageId(),
topics);
} else {
throw new IllegalArgumentException("AMQP message wrong body type");
}
}
示例13: from
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
/**
* Return an AMQP_SUBSCRIPTIONS message from the raw AMQP one
*
* @param message raw AMQP message
* @return AMQP_SUBSCRIPTIONS message
*/
@SuppressWarnings("unchecked")
public static AmqpSubscriptionsMessage from(Message message) {
if (!message.getSubject().equals(AMQP_SUBJECT)) {
throw new IllegalArgumentException(String.format("AMQP message subject is no s%", AMQP_SUBJECT));
}
Section section = message.getBody();
if ((section != null) && (section instanceof AmqpValue)) {
Map<String, String> map = (Map<String, String>) ((AmqpValue) section).getValue();
// build the unique topic subscriptions list
List<AmqpTopicSubscription> topicSubscriptions = new ArrayList<>();
for (Map.Entry<String, String> entry: map.entrySet()) {
topicSubscriptions.add(new AmqpTopicSubscription(entry.getKey(), MqttQoS.valueOf(Integer.valueOf(entry.getValue()))));
}
return new AmqpSubscriptionsMessage(topicSubscriptions);
} else {
throw new IllegalArgumentException("AMQP message wrong body type");
}
}
示例14: getQueueNames
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
public Set<String> getQueueNames() throws TimeoutException {
log.info("Retrieving queue names");
Message response = doOperation("broker", "getQueueNames");
Set<String> queues = new LinkedHashSet<>();
JsonArray payload = new JsonArray((String)((AmqpValue)response.getBody()).getValue());
for (int i = 0; i < payload.size(); i++) {
JsonArray inner = payload.getJsonArray(i);
for (int j = 0; j < inner.size(); j++) {
String queueName = inner.getString(j);
if (!queueName.equals(replyTo)) {
queues.add(queueName);
}
}
}
return queues;
}
示例15: testReceive
import org.apache.qpid.proton.amqp.messaging.AmqpValue; //导入依赖的package包/类
@Test
public void testReceive() throws InterruptedException {
try (BlockingClient client = new BlockingClient("127.0.0.1", 12345)) {
Message m = Message.Factory.create();
m.setAddress("testreceive");
m.setBody(new AmqpValue("hello there"));
outbox.put(m);
List<Message> messages = client.recv("testsend", 1, 1, TimeUnit.MINUTES);
assertThat(messages.size(), is(1));
Message received = messages.get(0);
assertNotNull(received);
assertThat(received.getMessageId(), is(m.getMessageId()));
assertThat(((AmqpValue)received.getBody()).getValue(), is("hello there"));
}
}