Search in sources :

Example 1 with MqttMessageForwarder

use of org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttMessageForwarder in project rocketmq-externals by apache.

the class ProduceMessageIntegrationTest method setup.

@Before
public void setup() {
    /* start the mocked MQTTBridge */
    clientManager = new ClientManagerImpl();
    subscriptionStore = Mockito.spy(new InMemorySubscriptionStore());
    mqttConnectMessageHandler = new MqttConnectMessageHandler(clientManager);
    mqttMessageForwarder = new MqttMessageForwarder(subscriptionStore);
    dispatcher = new MessageDispatcher(clientManager);
    dispatcher.registerHandler(Message.Type.MQTT_CONNECT, mqttConnectMessageHandler);
    dispatcher.registerHandler(Message.Type.MQTT_PUBLISH, mqttMessageForwarder);
    producerChannel = new EmbeddedChannel(dispatcher);
    mockedConsuemr = Mockito.spy(new MqttClient());
    mockedConsumerCtx = Mockito.mock(ChannelHandlerContext.class);
    mockedSubscriptions = new ArrayList<>();
    mockedSubscriptions.add(Subscription.Builder.newBuilder().client(mockedConsuemr).qos(0).build());
    Mockito.when(mockedConsuemr.getCtx()).thenReturn(mockedConsumerCtx);
    Mockito.when(mockedConsumerCtx.writeAndFlush(Mockito.any(MqttPublishMessage.class))).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            MqttPublishMessage publishMessage = (MqttPublishMessage) mock.getArguments()[0];
            consumerChannel.writeOutbound(publishMessage);
            return consumerChannel.newSucceededFuture();
        }
    });
}
Also used : MqttMessageForwarder(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttMessageForwarder) ClientManagerImpl(org.apache.rocketmq.iot.connection.client.impl.ClientManagerImpl) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) MqttConnectMessageHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttConnectMessageHandler) MqttClient(org.apache.rocketmq.iot.protocol.mqtt.data.MqttClient) MessageDispatcher(org.apache.rocketmq.iot.protocol.mqtt.handler.MessageDispatcher) MqttPublishMessage(io.netty.handler.codec.mqtt.MqttPublishMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) InMemorySubscriptionStore(org.apache.rocketmq.iot.storage.subscription.impl.InMemorySubscriptionStore) Before(org.junit.Before)

Example 2 with MqttMessageForwarder

use of org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttMessageForwarder in project rocketmq-externals by apache.

the class PubSubIntegrationTest method setup.

@Before
public void setup() {
    clientManager = new ClientManagerImpl();
    subscriptionStore = new InMemorySubscriptionStore();
    messageDispatcher = new MessageDispatcher(clientManager);
    mqttConnectMessageHandler = new MqttConnectMessageHandler(clientManager);
    mqttSubscribeMessageHandler = new MqttSubscribeMessageHandler(subscriptionStore);
    mqttMessageForwarder = new MqttMessageForwarder(subscriptionStore);
    messageDispatcher.registerHandler(Message.Type.MQTT_CONNECT, mqttConnectMessageHandler);
    messageDispatcher.registerHandler(Message.Type.MQTT_PUBLISH, mqttMessageForwarder);
    messageDispatcher.registerHandler(Message.Type.MQTT_SUBSCRIBE, mqttSubscribeMessageHandler);
    producer = Mockito.spy(new MqttClient());
    producer.setId(producerId);
    consumer = Mockito.spy(new MqttClient());
    consumer.setId(consumerId);
    producerChannel = new EmbeddedChannel(messageDispatcher);
    producer.setCtx(producerChannel.pipeline().context("producer-ctx"));
    consumerChannel = new EmbeddedChannel(messageDispatcher);
    consumer.setCtx(consumerChannel.pipeline().context("consumer-ctx"));
    topicSubscriptions.add(new MqttTopicSubscription(topicName, MqttQoS.AT_MOST_ONCE));
// Mockito.when(consumerCtx.writeAndFlush(Mockito.any(MqttMessage.class))).then(
// new Answer<Object>() {
// @Override public Object answer(InvocationOnMock mock) throws Throwable {
// MqttMessage message = (MqttMessage) mock.getArguments()[0];
// consumerChannel.writeOutbound(message);
// return consumerChannel.newSucceededFuture();
// }
// }
// );
}
Also used : MqttClient(org.apache.rocketmq.iot.protocol.mqtt.data.MqttClient) MessageDispatcher(org.apache.rocketmq.iot.protocol.mqtt.handler.MessageDispatcher) MqttMessageForwarder(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttMessageForwarder) ClientManagerImpl(org.apache.rocketmq.iot.connection.client.impl.ClientManagerImpl) MqttTopicSubscription(io.netty.handler.codec.mqtt.MqttTopicSubscription) MqttSubscribeMessageHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttSubscribeMessageHandler) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) MqttConnectMessageHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttConnectMessageHandler) InMemorySubscriptionStore(org.apache.rocketmq.iot.storage.subscription.impl.InMemorySubscriptionStore) Before(org.junit.Before)

Example 3 with MqttMessageForwarder

use of org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttMessageForwarder in project rocketmq-externals by apache.

the class MQTTBridge method registerMessageHandlers.

private void registerMessageHandlers() {
    messageDispatcher.registerHandler(Message.Type.MQTT_CONNECT, new MqttConnectMessageHandler(clientManager));
    messageDispatcher.registerHandler(Message.Type.MQTT_DISCONNECT, new MqttDisconnectMessageHandler(clientManager));
    messageDispatcher.registerHandler(Message.Type.MQTT_PUBLISH, new MqttMessageForwarder(subscriptionStore));
    // TODO qos 1/2 PUBLISH
    // TODO qos 1: PUBACK
    // TODO qos 2: PUBREC
    // TODO qos 2: PUBREL
    // TODO qos 2: PUBCOMP
    messageDispatcher.registerHandler(Message.Type.MQTT_PINGREQ, new MqttPingreqMessageHandler());
    messageDispatcher.registerHandler(Message.Type.MQTT_SUBSCRIBE, new MqttSubscribeMessageHandler(subscriptionStore));
    messageDispatcher.registerHandler(Message.Type.MQTT_UNSUBSCRIBE, new MqttUnsubscribeMessagHandler(subscriptionStore));
}
Also used : MqttDisconnectMessageHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttDisconnectMessageHandler) MqttMessageForwarder(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttMessageForwarder) MqttUnsubscribeMessagHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttUnsubscribeMessagHandler) MqttSubscribeMessageHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttSubscribeMessageHandler) MqttPingreqMessageHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttPingreqMessageHandler) MqttConnectMessageHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttConnectMessageHandler)

Example 4 with MqttMessageForwarder

use of org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttMessageForwarder in project rocketmq-externals by apache.

the class ConsumeMessageIntegrationTest method setup.

@Before
public void setup() {
    clientManager = new ClientManagerImpl();
    subscriptionStore = new InMemorySubscriptionStore();
    messageDispatcher = new MessageDispatcher(clientManager);
    mqttConnectMessageHandler = new MqttConnectMessageHandler(clientManager);
    mqttSubscribeMessageHandler = new MqttSubscribeMessageHandler(subscriptionStore);
    mqttMessageForwarder = new MqttMessageForwarder(subscriptionStore);
    messageDispatcher.registerHandler(Message.Type.MQTT_CONNECT, mqttConnectMessageHandler);
    messageDispatcher.registerHandler(Message.Type.MQTT_SUBSCRIBE, mqttSubscribeMessageHandler);
    messageDispatcher.registerHandler(Message.Type.MQTT_PUBLISH, mqttMessageForwarder);
    embeddedChannel = new EmbeddedChannel(messageDispatcher);
    subscriptions = new ArrayList<>();
    subscriptions.add(new MqttTopicSubscription(topicName, MqttQoS.AT_MOST_ONCE));
    consuemr = Mockito.spy(new MqttClient());
    consuermCtx = Mockito.mock(ChannelHandlerContext.class);
    Mockito.when(consuemr.getCtx()).thenReturn(consuermCtx);
}
Also used : MqttClient(org.apache.rocketmq.iot.protocol.mqtt.data.MqttClient) MessageDispatcher(org.apache.rocketmq.iot.protocol.mqtt.handler.MessageDispatcher) MqttMessageForwarder(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttMessageForwarder) ClientManagerImpl(org.apache.rocketmq.iot.connection.client.impl.ClientManagerImpl) MqttTopicSubscription(io.netty.handler.codec.mqtt.MqttTopicSubscription) MqttSubscribeMessageHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttSubscribeMessageHandler) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) MqttConnectMessageHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttConnectMessageHandler) InMemorySubscriptionStore(org.apache.rocketmq.iot.storage.subscription.impl.InMemorySubscriptionStore) Before(org.junit.Before)

Aggregations

MqttConnectMessageHandler (org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttConnectMessageHandler)4 MqttMessageForwarder (org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttMessageForwarder)4 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)3 ClientManagerImpl (org.apache.rocketmq.iot.connection.client.impl.ClientManagerImpl)3 MqttClient (org.apache.rocketmq.iot.protocol.mqtt.data.MqttClient)3 MessageDispatcher (org.apache.rocketmq.iot.protocol.mqtt.handler.MessageDispatcher)3 MqttSubscribeMessageHandler (org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttSubscribeMessageHandler)3 InMemorySubscriptionStore (org.apache.rocketmq.iot.storage.subscription.impl.InMemorySubscriptionStore)3 Before (org.junit.Before)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 MqttTopicSubscription (io.netty.handler.codec.mqtt.MqttTopicSubscription)2 MqttPublishMessage (io.netty.handler.codec.mqtt.MqttPublishMessage)1 MqttDisconnectMessageHandler (org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttDisconnectMessageHandler)1 MqttPingreqMessageHandler (org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttPingreqMessageHandler)1 MqttUnsubscribeMessagHandler (org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttUnsubscribeMessagHandler)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1