当前位置: 首页>>代码示例>>Java>>正文


Java Proton类代码示例

本文整理汇总了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();
    }
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:26,代码来源:AddressController.java

示例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;
}
 
开发者ID:strimzi,项目名称:amqp-kafka-bridge,代码行数:22,代码来源:AmqpRawMessageConverter.java

示例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;
}
 
开发者ID:strimzi,项目名称:amqp-kafka-bridge,代码行数:22,代码来源:AmqpDefaultMessageConverter.java

示例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();
    }
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:18,代码来源:ReactorLogger.java

示例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;
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:24,代码来源:DeferredSettlementTest.java

示例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);
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:24,代码来源:TransportImplTest.java

示例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();
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:18,代码来源:SimpleTest.java

示例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;
}
 
开发者ID:mqlight,项目名称:java-mqlight,代码行数:22,代码来源:NonBlockingClientImpl.java

示例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;
}
 
开发者ID:mqlight,项目名称:java-mqlight,代码行数:18,代码来源:NonBlockingClientImpl.java

示例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));
}
 
开发者ID:vert-x3,项目名称:vertx-amqp-bridge,代码行数:29,代码来源:MessageTranslatorImplTest.java

示例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));
}
 
开发者ID:vert-x3,项目名称:vertx-amqp-bridge,代码行数:20,代码来源:MessageTranslatorImplTest.java

示例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));
}
 
开发者ID:vert-x3,项目名称:vertx-amqp-bridge,代码行数:23,代码来源:MessageTranslatorImplTest.java

示例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;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:24,代码来源:JMSTransformationSpeedComparisonTest.java

示例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();
}
 
开发者ID:vert-x3,项目名称:vertx-amqp-service,代码行数:19,代码来源:AmqpPub.java

示例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();
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-proton,代码行数:18,代码来源:ProtonClientTest.java


注:本文中的org.apache.qpid.proton.Proton类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。