Example usage for io.netty.handler.codec.mqtt MqttMessageBuilders publish

List of usage examples for io.netty.handler.codec.mqtt MqttMessageBuilders publish

Introduction

In this page you can find the example usage for io.netty.handler.codec.mqtt MqttMessageBuilders publish.

Prototype

public static PublishBuilder publish() 

Source Link

Usage

From source file:io.crate.mqtt.netty.MqttMessages.java

License:Apache License

public static MqttMessageBuilders.PublishBuilder publishBuilder() {
    return MqttMessageBuilders.publish();
}

From source file:io.moquette.interception.RxBusTest.java

License:Open Source License

@SuppressWarnings("CheckReturnValue")
@Test/* w w  w .ja  va 2  s.c  o  m*/
public void test() {
    AtomicBoolean testRun = new AtomicBoolean(false);

    RxBus bus = new RxBus();

    bus.getEvents().filter(msg -> msg instanceof InterceptPublishMessage).cast(InterceptPublishMessage.class)
            .subscribe(msg -> {
                assertThat(msg.getUsername()).isEqualTo("username");
                assertThat(msg.getTopic().toString()).isEqualTo("topic");
                testRun.set(true);
            });

    MqttPublishMessage msg = MqttMessageBuilders.publish().topicName("topic").qos(MqttQoS.AT_LEAST_ONCE)
            .payload(Unpooled.EMPTY_BUFFER).build();
    bus.publish(new InterceptPublishMessage(msg, "clientID", "username", new Topic("topic")));

    assertThat(testRun.get()).isTrue();
}

From source file:io.moquette.spi.impl.AbstractProtocolProcessorCommonUtils.java

License:Open Source License

protected void internalPublishTo(String topic, MqttQoS qos, boolean retained) {
    MqttPublishMessage publish = MqttMessageBuilders.publish().topicName(topic).retained(retained).qos(qos)
            .payload(Unpooled.copiedBuffer(HELLO_WORLD_MQTT.getBytes(UTF_8))).build();
    this.m_processor.internalPublish(publish, "INTRPUBL");
}

From source file:io.moquette.spi.impl.AbstractProtocolProcessorCommonUtils.java

License:Open Source License

protected void publishToAs(EmbeddedChannel channel, String clientId, String topic, MqttQoS qos,
        boolean retained) {
    NettyUtils.userName(channel, clientId);
    MqttPublishMessage publish = MqttMessageBuilders.publish().topicName(topic).retained(retained).qos(qos)
            .payload(Unpooled.copiedBuffer(HELLO_WORLD_MQTT.getBytes(UTF_8))).build();
    this.m_processor.processPublish(m_channel, publish);
}

From source file:io.moquette.spi.impl.AbstractProtocolProcessorCommonUtils.java

License:Open Source License

protected void publishToAs(EmbeddedChannel channel, String clientId, String topic, String payload, MqttQoS qos,
        int messageId, boolean retained) {
    NettyUtils.userName(channel, clientId);
    MqttPublishMessage publish = MqttMessageBuilders.publish().topicName(topic).retained(retained)
            .messageId(messageId).qos(qos).payload(Unpooled.copiedBuffer(payload.getBytes(UTF_8))).build();
    this.m_processor.processPublish(channel, publish);
}

From source file:io.moquette.spi.impl.AbstractProtocolProcessorCommonUtils.java

License:Open Source License

protected void publishQoS2ToAs(EmbeddedChannel channel, String clientId, String topic, String payload,
        int messageId, boolean retained) {
    NettyUtils.userName(channel, clientId);
    MqttPublishMessage publish = MqttMessageBuilders.publish().topicName(topic).retained(retained)
            .messageId(messageId).qos(MqttQoS.EXACTLY_ONCE)
            .payload(Unpooled.copiedBuffer(payload.getBytes(UTF_8))).build();
    this.m_processor.processPublish(channel, publish);

    verifyPubrecIsReceived(channel, messageId);

    MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBREL, false, AT_LEAST_ONCE, false,
            0);//from  www .  j a v a2s.  c o  m
    MqttMessage pubRel = new MqttMessage(mqttFixedHeader, from(messageId));
    this.m_processor.processPubRel(channel, pubRel);

    verifyPubCompIsReceived(channel, messageId);
}