Search in sources :

Example 1 with Message

use of org.apache.rocketmq.iot.common.data.Message in project rocketmq-externals by apache.

the class MqttIdleHandlerTest method test.

@Test
public void test() throws Exception {
    Message message = new Message();
    idleHandler.channelActive(ctx);
    idleHandler.channelRead(ctx, message);
    idleHandler.channelReadComplete(ctx);
    // sleep for 2s
    Thread.sleep(2000);
    Mockito.verify(ctx).fireUserEventTriggered(Mockito.any(IdleStateEvent.class));
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) Message(org.apache.rocketmq.iot.common.data.Message) Test(org.junit.Test)

Example 2 with Message

use of org.apache.rocketmq.iot.common.data.Message in project rocketmq-externals by apache.

the class MqttPingreqMessageHandlerTest method testHandleMessage.

@Test
public void testHandleMessage() {
    Message message = new Message();
    message.setClient(client);
    message.setPayload(getMqttPingreqMessage());
    handler.handleMessage(message);
    Mockito.verify(ctx).writeAndFlush(Mockito.any(MqttMessage.class));
}
Also used : MqttMessage(io.netty.handler.codec.mqtt.MqttMessage) MqttMessage(io.netty.handler.codec.mqtt.MqttMessage) Message(org.apache.rocketmq.iot.common.data.Message) Test(org.junit.Test)

Example 3 with Message

use of org.apache.rocketmq.iot.common.data.Message in project rocketmq-externals by apache.

the class MessageDispatcher method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (!(msg instanceof MqttMessage)) {
        return;
    }
    Client client = clientManager.get(ctx.channel());
    if (client == null) {
        client = new MqttClient();
        client.setCtx(ctx);
        clientManager.put(ctx.channel(), client);
    }
    MqttMessage mqttMessage = (MqttMessage) msg;
    Message message = MessageUtil.getMessage(mqttMessage);
    message.setClient(client);
    dispatch(message);
}
Also used : MqttClient(org.apache.rocketmq.iot.protocol.mqtt.data.MqttClient) MqttMessage(io.netty.handler.codec.mqtt.MqttMessage) Message(org.apache.rocketmq.iot.common.data.Message) MqttMessage(io.netty.handler.codec.mqtt.MqttMessage) Client(org.apache.rocketmq.iot.connection.client.Client) MqttClient(org.apache.rocketmq.iot.protocol.mqtt.data.MqttClient)

Example 4 with Message

use of org.apache.rocketmq.iot.common.data.Message in project rocketmq-externals by apache.

the class MqttDispatcherTest method testChanelRead0.

public void testChanelRead0() {
    messageDispatcher.registerHandler(Message.Type.MQTT_CONNECT, mockedConnectMessageHandler);
    MqttConnectMessage mockedConnectMessage = Mockito.mock(MqttConnectMessage.class);
    Message mockedMessage = Mockito.spy(new Message());
    Mockito.when(MessageUtil.getMessage(mockedConnectMessage)).thenReturn(mockedMessage);
    EmbeddedChannel embeddedChannel = new EmbeddedChannel(messageDispatcher);
    embeddedChannel.writeInbound(mockedConnectMessage);
    Mockito.verify(mockedConnectMessageHandler).handleMessage(mockedMessage);
}
Also used : MqttConnectMessage(io.netty.handler.codec.mqtt.MqttConnectMessage) MqttConnectMessage(io.netty.handler.codec.mqtt.MqttConnectMessage) Message(org.apache.rocketmq.iot.common.data.Message) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel)

Example 5 with Message

use of org.apache.rocketmq.iot.common.data.Message in project rocketmq-externals by apache.

the class AbstractMqttMessageHandlerTest method initMessage.

private void initMessage() {
    message = new Message();
    setupMessage();
    message.setClient(client);
}
Also used : Message(org.apache.rocketmq.iot.common.data.Message)

Aggregations

Message (org.apache.rocketmq.iot.common.data.Message)6 MqttMessage (io.netty.handler.codec.mqtt.MqttMessage)3 MqttConnectMessage (io.netty.handler.codec.mqtt.MqttConnectMessage)2 Test (org.junit.Test)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 MqttConnAckMessage (io.netty.handler.codec.mqtt.MqttConnAckMessage)1 MqttPubAckMessage (io.netty.handler.codec.mqtt.MqttPubAckMessage)1 MqttPublishMessage (io.netty.handler.codec.mqtt.MqttPublishMessage)1 MqttSubAckMessage (io.netty.handler.codec.mqtt.MqttSubAckMessage)1 MqttSubscribeMessage (io.netty.handler.codec.mqtt.MqttSubscribeMessage)1 MqttUnsubAckMessage (io.netty.handler.codec.mqtt.MqttUnsubAckMessage)1 MqttUnsubscribeMessage (io.netty.handler.codec.mqtt.MqttUnsubscribeMessage)1 IdleStateEvent (io.netty.handler.timeout.IdleStateEvent)1 Client (org.apache.rocketmq.iot.connection.client.Client)1 MqttClient (org.apache.rocketmq.iot.protocol.mqtt.data.MqttClient)1