Search in sources :

Example 6 with MqttTopicSubscription

use of io.netty.handler.codec.mqtt.MqttTopicSubscription in project activemq-artemis by apache.

the class MQTTSubscriptionManager method addSubscription.

private void addSubscription(MqttTopicSubscription subscription) throws Exception {
    String topicName = CompositeAddress.extractAddressName(subscription.topicName());
    MqttTopicSubscription s = session.getSessionState().getSubscription(topicName);
    int qos = subscription.qualityOfService().value();
    String coreAddress = MQTTUtil.convertMQTTAddressFilterToCore(topicName, session.getWildcardConfiguration());
    session.getSessionState().addSubscription(subscription, session.getWildcardConfiguration());
    Queue q = createQueueForSubscription(coreAddress, qos);
    if (s == null) {
        createConsumerForSubscriptionQueue(q, topicName, qos);
    } else {
        consumerQoSLevels.put(consumers.get(topicName).getID(), qos);
    }
    session.getRetainMessageManager().addRetainedMessagesToQueue(q, topicName);
}
Also used : MqttTopicSubscription(io.netty.handler.codec.mqtt.MqttTopicSubscription) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 7 with MqttTopicSubscription

use of io.netty.handler.codec.mqtt.MqttTopicSubscription 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 8 with MqttTopicSubscription

use of io.netty.handler.codec.mqtt.MqttTopicSubscription 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

MqttTopicSubscription (io.netty.handler.codec.mqtt.MqttTopicSubscription)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 MqttClient (org.apache.rocketmq.iot.protocol.mqtt.data.MqttClient)3 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 MqttMessageIdVariableHeader (io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader)2 MqttSubscribeMessage (io.netty.handler.codec.mqtt.MqttSubscribeMessage)2 ArrayList (java.util.ArrayList)2 Queue (org.apache.activemq.artemis.core.server.Queue)2 ClientManagerImpl (org.apache.rocketmq.iot.connection.client.impl.ClientManagerImpl)2 MessageDispatcher (org.apache.rocketmq.iot.protocol.mqtt.handler.MessageDispatcher)2 MqttConnectMessageHandler (org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttConnectMessageHandler)2 MqttMessageForwarder (org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttMessageForwarder)2 MqttSubscribeMessageHandler (org.apache.rocketmq.iot.protocol.mqtt.handler.downstream.impl.MqttSubscribeMessageHandler)2 InMemorySubscriptionStore (org.apache.rocketmq.iot.storage.subscription.impl.InMemorySubscriptionStore)2 Before (org.junit.Before)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 MqttConnAckVariableHeader (io.netty.handler.codec.mqtt.MqttConnAckVariableHeader)1 MqttConnectMessage (io.netty.handler.codec.mqtt.MqttConnectMessage)1 MqttConnectPayload (io.netty.handler.codec.mqtt.MqttConnectPayload)1 MqttConnectVariableHeader (io.netty.handler.codec.mqtt.MqttConnectVariableHeader)1