use of org.apache.rocketmq.iot.connection.client.impl.ClientManagerImpl 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();
}
});
}
use of org.apache.rocketmq.iot.connection.client.impl.ClientManagerImpl in project rocketmq-externals by apache.
the class MQTTBridge method init.
private void init() {
bossGroup = new NioEventLoopGroup(MQTTBridgeConfiguration.threadNumOfBossGroup());
workerGroup = new NioEventLoopGroup(MQTTBridgeConfiguration.threadNumOfWorkerGroup());
serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup).localAddress(MQTTBridgeConfiguration.port()).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, MQTTBridgeConfiguration.socketBacklog()).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("mqtt-decoder", new MqttDecoder());
pipeline.addLast("mqtt-encoder", MqttEncoder.INSTANCE);
pipeline.addLast("channel-idle-handler", new MqttIdleHandler());
pipeline.addLast("message-dispatcher", messageDispatcher);
pipeline.addLast("connection-manager", connectionHandler);
}
});
subscriptionStore = new InMemorySubscriptionStore();
clientManager = new ClientManagerImpl();
messageDispatcher = new MessageDispatcher(clientManager);
connectionHandler = new MqttConnectionHandler(clientManager, subscriptionStore);
registerMessageHandlers();
}
use of org.apache.rocketmq.iot.connection.client.impl.ClientManagerImpl 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 org.apache.rocketmq.iot.connection.client.impl.ClientManagerImpl 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);
}
use of org.apache.rocketmq.iot.connection.client.impl.ClientManagerImpl in project rocketmq-externals by apache.
the class ClientManagerTest method setup.
@Before
public void setup() throws IllegalAccessException {
clientManager = new ClientManagerImpl();
client = Mockito.mock(Client.class);
channel = Mockito.mock(Channel.class);
channel2client = (Map<Channel, Client>) FieldUtils.getDeclaredField(ClientManagerImpl.class, "channel2Client", true).get(clientManager);
channel2client.put(channel, client);
}
Aggregations