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);
}
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();
// }
// }
// );
}
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);
}
Aggregations