本文整理汇总了Java中org.apache.qpid.proton.Proton类的典型用法代码示例。如果您正苦于以下问题:Java Proton类的具体用法?Java Proton怎么用?Java Proton使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Proton类属于org.apache.qpid.proton包,在下文中一共展示了Proton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkRouter
import org.apache.qpid.proton.Proton; //导入依赖的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();
}
}
示例2: toMessage
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
@Override
public Message toMessage(String address, ConsumerRecord<String, byte[]> record) {
Message message = Proton.message();
message.setAddress(address);
message.decode(record.value(), 0, record.value().length);
// 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());
if (record.key() != null)
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);
return message;
}
示例3: toMessage
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
@Override
public Message toMessage(String address, ConsumerRecord<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());
if (record.key() != null)
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;
}
示例4: main
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
// You can pass multiple handlers to a reactor when you construct it.
// Each of these handlers will see every event the reactor sees. By
// combining this with on_unhandled, you can log each event that goes
// to the reactor.
Reactor reactor = Proton.reactor(new ReactorLogger(), new Logger());
reactor.run();
// Note that if you wanted to add the logger later, you could also
// write the above as below. All arguments to the reactor are just
// added to the default handler for the reactor.
reactor = Proton.reactor(new ReactorLogger());
if (loggingEnabled)
reactor.getHandler().add(new Logger());
reactor.run();
}
示例5: sendMessageToClient
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
private Delivery sendMessageToClient(String deliveryTag, int messageBody)
{
byte[] tag = deliveryTag.getBytes(StandardCharsets.UTF_8);
Message m = Proton.message();
m.setBody(new AmqpValue(messageBody));
byte[] encoded = new byte[BUFFER_SIZE];
int len = m.encode(encoded, 0, BUFFER_SIZE);
assertTrue("given array was too small", len < BUFFER_SIZE);
Sender serverSender = getServer().getSender();
Delivery serverDelivery = serverSender.delivery(tag);
int sent = serverSender.send(encoded, 0, len);
assertEquals("sender unable to send all data at once as assumed for simplicity", len, sent);
boolean senderAdvanced = serverSender.advance();
assertTrue("sender has not advanced", senderAdvanced);
return serverDelivery;
}
示例6: testOpenSessionBeforeOpenConnection
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
@Test
public void testOpenSessionBeforeOpenConnection()
{
MockTransportImpl transport = new MockTransportImpl();
Connection connection = Proton.connection();
transport.bind(connection);
Session session = connection.session();
session.open();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 0, transport.writes.size());
connection.open();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());
assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
}
示例7: test
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
@Test
public void test()
{
Connection connection1 = Proton.connection();
Connection connection2 = Proton.connection();;
Transport transport1 = Proton.transport();
transport1.bind(connection1);
Transport transport2 = Proton.transport();
transport2.bind(connection2);
assertEquals(EndpointState.UNINITIALIZED, connection1.getLocalState());
assertEquals(EndpointState.UNINITIALIZED, connection1.getRemoteState());
connection1.open();
connection2.open();
}
示例8: send
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
@Override
public <T> boolean send(String topic, String data, Map<String, Object> properties,
SendOptions sendOptions, CompletionListener<T> listener, T context)
throws StoppedException {
final String methodName = "send";
logger.entry(this, methodName, topic, data, properties, sendOptions, listener, context);
if (data == null) {
final IllegalArgumentException exception = new IllegalArgumentException("data cannot be null");
logger.throwing(this, methodName, exception);
throw exception;
}
org.apache.qpid.proton.message.Message protonMsg = Proton.message();
protonMsg.setBody(new AmqpValue(data));
final boolean result = send(topic, protonMsg, properties, sendOptions == null ? defaultSendOptions : sendOptions, listener, context);
logger.exit(this, methodName, result);
return result;
}
示例9: sendJson
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
@Override
public <T> boolean sendJson(String topic, String json,
Map<String, Object> properties, SendOptions sendOptions,
CompletionListener<T> listener, T context)
throws StoppedException {
final String methodName = "sendJson";
logger.entry(this, methodName, topic, json, properties, sendOptions, listener, context);
org.apache.qpid.proton.message.Message protonMsg = Proton.message();
protonMsg.setBody(new AmqpValue(json));
protonMsg.setContentType("application/json");
final boolean result = send(topic, protonMsg, properties, sendOptions == null ? defaultSendOptions : sendOptions, listener, context);
logger.exit(this, methodName, result);
return result;
}
示例10: testAMQP_to_JSON_VerifyApplicationPropertySymbol
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
/**
* Verifies that a Symbol application property is converted to a String [by the JsonObject]
*/
@Test
public void testAMQP_to_JSON_VerifyApplicationPropertySymbol() {
Map<String, Object> props = new HashMap<>();
ApplicationProperties appProps = new ApplicationProperties(props);
String symbolPropKey = "symbolPropKey";
Symbol symbolPropValue = Symbol.valueOf("symbolPropValue");
props.put(symbolPropKey, symbolPropValue);
Message protonMsg = Proton.message();
protonMsg.setApplicationProperties(appProps);
JsonObject jsonObject = translator.convertToJsonObject(protonMsg);
assertNotNull("expected converted msg", jsonObject);
assertTrue("expected application properties element key to be present",
jsonObject.containsKey(AmqpConstants.APPLICATION_PROPERTIES));
JsonObject jsonAppProps = jsonObject.getJsonObject(AmqpConstants.APPLICATION_PROPERTIES);
assertNotNull("expected application properties element value to be non-null", jsonAppProps);
assertTrue("expected key to be present", jsonAppProps.containsKey(symbolPropKey));
assertEquals("expected value to be equal, as a string", symbolPropValue.toString(),
jsonAppProps.getValue(symbolPropKey));
}
示例11: testAMQP_to_JSON_VerifyBodyWithDataSection
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
@Test
public void testAMQP_to_JSON_VerifyBodyWithDataSection() {
String testContent = "myTestContent";
Data data = new Data(new Binary(testContent.getBytes(StandardCharsets.UTF_8)));
Message protonMsg = Proton.message();
protonMsg.setBody(data);
JsonObject jsonObject = translator.convertToJsonObject(protonMsg);
assertNotNull("expected converted msg", jsonObject);
assertTrue("expected body element key to be present", jsonObject.containsKey(AmqpConstants.BODY));
assertNotNull("expected body element value to be non-null", jsonObject.getValue(AmqpConstants.BODY));
assertTrue("expected body_type element key to be present", jsonObject.containsKey(AmqpConstants.BODY_TYPE));
assertEquals("unexpected body_type value", AmqpConstants.BODY_TYPE_DATA,
jsonObject.getValue(AmqpConstants.BODY_TYPE));
jsonObject.put(AmqpConstants.BODY_TYPE, AmqpConstants.BODY_TYPE_VALUE);
assertArrayEquals("body content not as expected", testContent.getBytes(StandardCharsets.UTF_8),
jsonObject.getBinary(AmqpConstants.BODY));
}
示例12: testAMQP_to_JSON_VerifyBodyWithAmqpSequence
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
@Test
public void testAMQP_to_JSON_VerifyBodyWithAmqpSequence() {
String testContent = "myTestContent";
List<Object> elements = new ArrayList<>();
elements.add(new Binary(testContent.getBytes(StandardCharsets.UTF_8)));
Message protonMsg = Proton.message();
protonMsg.setBody(new AmqpSequence(elements));
JsonObject jsonObject = translator.convertToJsonObject(protonMsg);
assertNotNull("expected converted msg", jsonObject);
assertTrue("expected body element key to be present", jsonObject.containsKey(AmqpConstants.BODY));
assertNotNull("expected body element value to be non-null", jsonObject.getValue(AmqpConstants.BODY));
assertTrue("expected body_type element key to be present", jsonObject.containsKey(AmqpConstants.BODY_TYPE));
assertEquals("unexpected body_type value", AmqpConstants.BODY_TYPE_SEQUENCE,
jsonObject.getValue(AmqpConstants.BODY_TYPE));
JsonArray jsonSequence = jsonObject.getJsonArray(AmqpConstants.BODY);
assertArrayEquals("sequence element value not as expected", testContent.getBytes(StandardCharsets.UTF_8),
jsonSequence.getBinary(0));
assertTrue("expected body_type element key to be present", jsonObject.containsKey(AmqpConstants.BODY_TYPE));
}
示例13: createTypicalQpidJMSMessage
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
private Message createTypicalQpidJMSMessage() {
Map<String, Object> applicationProperties = new HashMap<>();
Map<Symbol, Object> messageAnnotations = new HashMap<>();
applicationProperties.put("property-1", "string");
applicationProperties.put("property-2", 512);
applicationProperties.put("property-3", true);
messageAnnotations.put(Symbol.valueOf("x-opt-jms-msg-type"), 0);
messageAnnotations.put(Symbol.valueOf("x-opt-jms-dest"), 0);
Message message = Proton.message();
message.setAddress("queue://test-queue");
message.setDeliveryCount(1);
message.setApplicationProperties(new ApplicationProperties(applicationProperties));
message.setMessageAnnotations(new MessageAnnotations(messageAnnotations));
message.setCreationTime(System.currentTimeMillis());
message.setContentType("text/plain");
message.setBody(new AmqpValue("String payload for AMQP message conversion performance testing."));
return message;
}
示例14: main
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Messenger mng = Proton.messenger();
mng.start();
Message msg = Proton.message();
msg.setBody(new AmqpValue("hello world from foo bar"));
msg.setAddress("amqp://localhost:5673/foo.bar");
mng.put(msg);
mng.send();
System.out.println("AMQP publisher sent message 'hello world from foo bar'");
msg.setBody(new AmqpValue("hello world from foo baz"));
msg.setAddress("amqp://localhost:5673/foo.baz");
mng.put(msg);
mng.send();
System.out.println("AMQP publisher sent message 'hello world from foo baz'");
mng.stop();
}
示例15: testAnonymousSenderEnforcesMessageHasAddress
import org.apache.qpid.proton.Proton; //导入依赖的package包/类
@Test(timeout = 20000)
public void testAnonymousSenderEnforcesMessageHasAddress(TestContext context) {
Async async = context.async();
connect(context, connection -> {
connection.open();
ProtonSender sender = connection.createSender(null);
Message messageWithNoAddress = Proton.message();
try {
sender.send(messageWithNoAddress);
context.fail("Send should have thrown IAE due to lack of message address");
} catch (IllegalArgumentException iae) {
// Expected
connection.disconnect();
async.complete();
}
});
}