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


Java Section类代码示例

本文整理汇总了Java中org.apache.qpid.proton.amqp.messaging.Section的典型用法代码示例。如果您正苦于以下问题:Java Section类的具体用法?Java Section怎么用?Java Section使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Section类属于org.apache.qpid.proton.amqp.messaging包,在下文中一共展示了Section类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleWeatherMessage

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的package包/类
/**
 * handleWeatherMessage takes received telemetry message and processes it to be printed to command line.
 * @param msg Telemetry message received through hono server.
 */
private void handleWeatherMessage(final Message msg) {
    final Section body = msg.getBody();
    //Ensures that message is Data (type of AMQP messaging). Otherwise exits method.
    if (!(body instanceof Data))
        return;
    //Gets deviceID.
    final String deviceID = MessageHelper.getDeviceId(msg);
    //Creates JSON parser to read input telemetry weather data. Prints data to console output.
    JSONParser parser = new JSONParser();
    try {
        Object obj = parser.parse(((Data) msg.getBody()).getValue().toString());
        JSONObject payload = (JSONObject) obj;
        System.out.println(new StringBuilder("Device: ").append(deviceID).append("; Location: ").
                append(payload.get("location")).append("; Temperature:").append(payload.get("temperature")));
    } catch (ParseException e) {
        System.out.println("Data was not sent in a readable way. Check telemetry input.");
        e.printStackTrace();
    }
}
 
开发者ID:rhiot,项目名称:hono-weather-demo,代码行数:24,代码来源:WeatherDataConsumer.java

示例2: receiverHandler

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的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);
    }
 
开发者ID:EnMasseProject,项目名称:enmasse-workshop,代码行数:21,代码来源:AmqpClient.java

示例3: handleMessage

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的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());
    }
}
 
开发者ID:eclipse,项目名称:hono,代码行数:17,代码来源:ExampleReceiver.java

示例4: handleMessage

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的package包/类
/**
 * Handler method for a Message from Hono that was received as telemetry or event data.
 * <p>
 * The payload, the content-type and the application properties will be printed to stdout.
 * @param msg The message that was received.
 */
private void handleMessage(final Message msg) {
    final Section body = msg.getBody();
    if (!(body instanceof Data)) {
        return;
    }

    final String content = ((Data) msg.getBody()).getValue().toString();

    final String deviceId = MessageHelper.getDeviceId(msg);

    final StringBuilder sb = new StringBuilder("received message [device: ").
            append(deviceId).append(", content-type: ").append(msg.getContentType()).append(" ]: ").append(content);

    if (msg.getApplicationProperties() != null) {
        sb.append(" with application properties: ").append(msg.getApplicationProperties().getValue());
    }

    System.out.println(sb.toString());
}
 
开发者ID:eclipse,项目名称:hono,代码行数:26,代码来源:HonoConsumerBase.java

示例5: getJSONValue

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Map<String, Object> getJSONValue(final Section message) {
    ObjectMapper objectMapper = new ObjectMapper();
    Map<String, Object> result;
    try {
        result = objectMapper.readValue(getValue(message),
                HashMap.class);
        if (result == null) {
            result = Collections.emptyMap();
        }
    } catch (IOException e) {
        LOGGER.warn("Could not parse the received message", e);
        result = Collections.emptyMap();
    }
    return result;
}
 
开发者ID:eclipse,项目名称:hono,代码行数:17,代码来源:HonoReceiver.java

示例6: from

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的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");
    }
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:27,代码来源:AmqpUnsubscribeMessage.java

示例7: from

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的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");
    }
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:31,代码来源:AmqpSubscriptionsMessage.java

示例8: doJSON_to_AMQP_VerifyStringBodyTestImpl

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的package包/类
private void doJSON_to_AMQP_VerifyStringBodyTestImpl(boolean setBodyType) {
  String testContent = "myTestContent";

  JsonObject jsonObject = new JsonObject();
  jsonObject.put(AmqpConstants.BODY, testContent);
  if(setBodyType){
    jsonObject.put(AmqpConstants.BODY_TYPE, AmqpConstants.BODY_TYPE_VALUE);
  }

  Message protonMsg = translator.convertToAmqpMessage(jsonObject);

  assertNotNull("Expected converted msg", protonMsg);
  Section body = protonMsg.getBody();
  assertTrue("Unexpected body type", body instanceof AmqpValue);
  assertEquals("Unexpected message body value", testContent, ((AmqpValue) body).getValue());
}
 
开发者ID:vert-x3,项目名称:vertx-amqp-bridge,代码行数:17,代码来源:MessageTranslatorImplTest.java

示例9: testJSON_to_AMQP_VerifyDataBody

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的package包/类
@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());
}
 
开发者ID:vert-x3,项目名称:vertx-amqp-bridge,代码行数:18,代码来源:MessageTranslatorImplTest.java

示例10: setObject

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的package包/类
@Override
public void setObject(Serializable value) throws IOException {
    if (value == null) {
        parent.setBody(NULL_OBJECT_BODY);
        encodedBody = null;
    } else if (isSupportedAmqpValueObjectType(value)) {
        // Exchange the incoming body value for one that is created from encoding
        // and decoding the value. Save the bytes for subsequent getObject and
        // copyInto calls to use.
        encodedBody = AmqpCodec.encode(new AmqpValue(value));
        Section decodedBody = AmqpCodec.decode(encodedBody);

        // This step requires a heavy-weight operation of both encoding and decoding the
        // incoming body value in order to create a copy such that changes to the original
        // do not affect the stored value, and also verifies we can actually encode it at all
        // now instead of later during send. In the future it makes sense to try to enhance
        // proton such that we can encode the body and use those bytes directly on the
        // message as it is being sent.

        parent.setBody(decodedBody);
    } else {
        // TODO: Data and AmqpSequence?
        throw new IllegalArgumentException("Encoding this object type with the AMQP type system is not supported: " + value.getClass().getName());
    }
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:26,代码来源:AmqpTypedObjectDelegate.java

示例11: setBody

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
void setBody(Section body) {
    if (body == null) {
        initializeEmptyBody();
    } else if (body instanceof AmqpValue) {
        Object o = ((AmqpValue) body).getValue();
        if (o == null) {
            initializeEmptyBody();
        } else if (o instanceof Map) {
            messageBodyMap = (Map<String, Object>) o;
            super.setBody(body);
        } else {
            throw new IllegalStateException("Unexpected message body type: " + body.getClass().getSimpleName());
        }
    } else {
        throw new IllegalStateException("Unexpected message body type: " + body.getClass().getSimpleName());
    }
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:20,代码来源:AmqpJmsMapMessageFacade.java

示例12: testSetObjectOnNewMessage

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的package包/类
/**
 * Test that setting an object on a new message results in the expected
 * content in the body section of the underlying message.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testSetObjectOnNewMessage() throws Exception {
    String content = "myStringContent";

    AmqpJmsObjectMessageFacade amqpObjectMessageFacade = createNewObjectMessageFacade(false);
    amqpObjectMessageFacade.setObject(content);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(content);
    oos.flush();
    oos.close();
    byte[] bytes = baos.toByteArray();

    // retrieve the bytes from the underlying message, check they match expectation
    Section section = amqpObjectMessageFacade.getBody();
    assertNotNull(section);
    assertEquals(Data.class, section.getClass());
    assertArrayEquals("Underlying message data section did not contain the expected bytes", bytes, ((Data) section).getValue().getArray());
}
 
开发者ID:apache,项目名称:qpid-jms,代码行数:27,代码来源:AmqpJmsObjectMessageFacadeTest.java

示例13: run

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的package包/类
public void run() {

        Vertx vertx = Vertx.vertx();

        ProtonClient client = ProtonClient.create(vertx);

        client.connect("localhost", 5673, res -> {

            if (res.succeeded()) {
                System.out.println("Connection successfull");

                ProtonConnection connection = res.result();
                connection.open();

                ProtonReceiver receiver = connection.createReceiver("test");

                receiver.handler((delivery, message) -> {

                    Section body = message.getBody();
                    if (body instanceof Data) {
                        byte[] value = ((Data) body).getValue().getArray();
                        System.out.println(new String(value));
                    }

                })
                .open();
            }
        });


        try {
            System.in.read();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
 
开发者ID:ppatierno,项目名称:kafka-connect-amqp,代码行数:38,代码来源:AmqpReceiver.java

示例14: getValue

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的package包/类
private byte[] getValue(final Section body) {
    if (body instanceof Data) {
        return ((Data) body).getValue().getArray();
    } else if (body instanceof AmqpValue) {
        return ((AmqpValue) body).getValue().toString().getBytes(StandardCharsets.UTF_8);
    } else {
        return new byte[0];
    }
}
 
开发者ID:eclipse,项目名称:hono,代码行数:10,代码来源:HonoReceiver.java

示例15: getToken

import org.apache.qpid.proton.amqp.messaging.Section; //导入依赖的package包/类
private void getToken(final ProtonConnection openCon, final Future<HonoUser> authResult) {

        final ProtonMessageHandler messageHandler = (delivery, message) -> {

            String type = MessageHelper.getApplicationProperty(
                    message.getApplicationProperties(),
                    AuthenticationConstants.APPLICATION_PROPERTY_TYPE,
                    String.class);

            if (AuthenticationConstants.TYPE_AMQP_JWT.equals(type)) {
                Section body = message.getBody();
                if (body instanceof AmqpValue) {
                    final String token = ((AmqpValue) body).getValue().toString();
                    HonoUser user = new HonoUserAdapter() {
                        @Override
                        public String getToken() {
                            return token;
                        }
                    };
                    LOG.debug("successfully retrieved token from Authentication service");
                    authResult.complete(user);

                } else {
                    authResult.fail("message from Authentication service contains no body");
                }

            } else {
                authResult.fail("Authentication service issued unsupported token [type: " + type + "]");
            }
        };

        openReceiver(openCon, messageHandler).compose(openReceiver -> {
            LOG.debug("opened receiver link to Authentication service, waiting for token ...");
        }, authResult);
    }
 
开发者ID:eclipse,项目名称:hono,代码行数:36,代码来源:AuthenticationServerClient.java


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