当前位置: 首页>>代码示例>>Java>>正文


Java IMqttAsyncClient类代码示例

本文整理汇总了Java中org.eclipse.paho.client.mqttv3.IMqttAsyncClient的典型用法代码示例。如果您正苦于以下问题:Java IMqttAsyncClient类的具体用法?Java IMqttAsyncClient怎么用?Java IMqttAsyncClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IMqttAsyncClient类属于org.eclipse.paho.client.mqttv3包,在下文中一共展示了IMqttAsyncClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: builderWithMocks

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
private Builder builderWithMocks(final String expectedClientId) {
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    Mockito.when(client.getClientId()).thenReturn(expectedClientId);
    final CloseFactory closeFactory = Mockito.mock(CloseFactory.class);
    final ConnectFactory connectFactory = Mockito.mock(ConnectFactory.class);
    final DisconnectFactory disconnectFactory = Mockito.mock(DisconnectFactory.class);
    final PublishFactory publishFactory = Mockito.mock(PublishFactory.class);
    final SubscribeFactory subscribeFactory = Mockito.mock(SubscribeFactory.class);
    final UnsubscribeFactory unsubscribeFactory = Mockito.mock(UnsubscribeFactory.class);
    return new PahoObservableMqttClient.Builder(client)
            .setCloseFactory(closeFactory)
            .setConnectFactory(connectFactory)
            .setDisconnectFactory(disconnectFactory)
            .setPublishFactory(publishFactory)
            .setSubscribeFactory(subscribeFactory)
            .setUnsubscribeFactory(unsubscribeFactory);
}
 
开发者ID:patrickvankann,项目名称:rxmqtt,代码行数:18,代码来源:PahoObservableMqttClientTest.java

示例2: whenCreateIsCalledThenAnObservableIsReturned

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    final SubscribeFactory factory = new SubscribeFactory(client);
    final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);
    final ArgumentCaptor<IMqttMessageListener[]> messageListener = ArgumentCaptor.forClass(IMqttMessageListener[].class);
    final String[] topics = new String[]{ "topic1", "topic2" };
    final int[] qos = new int[]{ 1, 2 };
    final Flowable<MqttMessage> obs = factory.create(topics, qos, BackpressureStrategy.ERROR);
    Assert.assertNotNull(obs);
    obs.subscribe();
    Mockito.verify(client).subscribe(Mockito.same(topics),
            Mockito.same(qos),
            Mockito.isNull(),
            actionListener.capture(),
            messageListener.capture());
    Assert.assertTrue(actionListener.getValue() instanceof SubscribeFactory.SubscribeActionListener);
    Assert.assertTrue(messageListener.getValue() instanceof SubscriberMqttMessageListener[]);
    Assert.assertEquals(2, messageListener.getValue().length);
}
 
开发者ID:patrickvankann,项目名称:rxmqtt,代码行数:21,代码来源:SubscribeFactoryTest.java

示例3: whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled() throws Throwable {
    expectedException.expectCause(isA(MqttException.class));
    final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);
    final ArgumentCaptor<IMqttMessageListener[]> messageListener = ArgumentCaptor.forClass(IMqttMessageListener[].class);
    final String[] topics = new String[]{ "topic1", "topic2" };
    final int[] qos = new int[]{ 1, 2 };
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    Mockito.when(client.subscribe(Mockito.same(topics),
            Mockito.same(qos),
            Mockito.isNull(),
            actionListener.capture(),
            messageListener.capture()))
            .thenThrow(new MqttException(MqttException.REASON_CODE_CLIENT_CONNECTED));
    final SubscribeFactory factory = new SubscribeFactory(client);
    final Flowable<MqttMessage> obs = factory.create(topics, qos, BackpressureStrategy.ERROR);
    obs.blockingFirst();
}
 
开发者ID:patrickvankann,项目名称:rxmqtt,代码行数:19,代码来源:SubscribeFactoryTest.java

示例4: whenCreateIsCalledThenAnObservableIsReturned

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
    // Given
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    final PublishFactory factory = new PublishFactory(client);
    final String topic = "topic1";
    final MqttMessage msg = MqttMessage.create(0, new byte[] { 'a',  'b',  'c' }, 1, true);
    final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);

    // When
    final Single<PublishToken> obs = factory.create(topic, msg);

    // Then
    Assert.assertNotNull(obs);
    obs.subscribe();
    Mockito.verify(client).publish(Mockito.same(topic), 
            Mockito.same(msg.getPayload()), Mockito.anyInt(),
            Mockito.anyBoolean(), Mockito.any(),
            actionListener.capture());
    Assert.assertTrue(actionListener.getValue() instanceof PublishFactory.PublishActionListener);
}
 
开发者ID:patrickvankann,项目名称:rxmqtt,代码行数:22,代码来源:PublishFactoryTest.java

示例5: whenCreateIsCalledThenAnObservableIsReturned

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
    // Given
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    final UnsubscribeFactory factory = new UnsubscribeFactory(client);
    final String[] topics = new String[]{ "topic1", "topic2" };
    final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);

    // When
    final Completable obs = factory.create(topics);

    // Then
    Assert.assertNotNull(obs);
    obs.subscribe();
    Mockito.verify(client).unsubscribe(Mockito.same(topics), Mockito.isNull(),
            actionListener.capture());
    Assert.assertTrue(actionListener.getValue() instanceof UnsubscribeFactory.UnsubscribeActionListener);
}
 
开发者ID:patrickvankann,项目名称:rxmqtt,代码行数:19,代码来源:UnsubscribeFactoryTest.java

示例6: whenCreateIsCalledThenAnObservableIsReturned

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
    // Given
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    final DisconnectFactory factory = new DisconnectFactory(client);
    final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);

    // When
    final Completable obs = factory.create();

    // Then
    Assert.assertNotNull(obs);
    obs.subscribe();
    Mockito.verify(client).disconnect(Mockito.isNull(),
            actionListener.capture());
    Assert.assertTrue(actionListener.getValue() instanceof DisconnectFactory.DisconnectActionListener);
}
 
开发者ID:patrickvankann,项目名称:rxmqtt,代码行数:18,代码来源:DisconnectFactoryTest.java

示例7: stop

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Stop
public void stop() {
    LOG.info("Mqttv3Client stoping!");

    if (clnt != null) {
        for (Entry<String, ObjectPool<IMqttAsyncClient>> entry : clnt.entrySet()) {
            try {
                entry.getValue().close();
            } catch (Exception e) {
                LOG.error(e.getMessage(), e.fillInStackTrace());
            }
        }
        clnt = null;
    }

    LOG.info("Mqttv3Client finish stoping!");
}
 
开发者ID:dzh,项目名称:jframe,代码行数:18,代码来源:Mqttv3ClientImpl.java

示例8: MqttCallBackImpl

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
public MqttCallBackImpl (IMqttAsyncClient  client,String clientID,String logLevel,String encoding) {
	super(encoding);    	
   	this.clientID = clientID;
	this.logLevel = logLevel;
	this.client = client;
	this.encoding = encoding;
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:8,代码来源:MqttCallBackImpl.java

示例9: Builder

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
public Builder(final IMqttAsyncClient client) {
    this.client = client;
    this.connectOptions = new MqttConnectOptions();
    this.closeFactory = new CloseFactory(client);
    this.connectFactory = new ConnectFactory(this.client, this.connectOptions);
    this.disconnectFactory = new DisconnectFactory(client);
    this.publishFactory = new PublishFactory(client);
    this.subscribeFactory = new SubscribeFactory(client);
    this.unsubscribeFactory = new UnsubscribeFactory(client);
    this.backpressureStrategy = BackpressureStrategy.BUFFER;
}
 
开发者ID:patrickvankann,项目名称:rxmqtt,代码行数:12,代码来源:PahoObservableMqttClient.java

示例10: whenAValidBackpressureStrategyThenTheAccessorReturnsIt

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenAValidBackpressureStrategyThenTheAccessorReturnsIt() throws MqttException {
    BackpressureStrategy expected = BackpressureStrategy.BUFFER;
    Builder builder = PahoObservableMqttClient.builder(Mockito.mock(IMqttAsyncClient.class))
    .setBackpressureStrategy(expected);
    Assert.assertNotNull(builder);
    Assert.assertNotNull(builder.getBackpressureStrategy());
    Assert.assertEquals(expected, builder.getBackpressureStrategy());
}
 
开发者ID:patrickvankann,项目名称:rxmqtt,代码行数:10,代码来源:PahoObservableMqttClientTest.java

示例11: whenGetClientIdIsCalledItReturnsPahoClientId

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenGetClientIdIsCalledItReturnsPahoClientId() {
    final String expectedClientId = "clientId";
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    Mockito.when(client.getClientId()).thenReturn(expectedClientId);
    final Builder builder = new PahoObservableMqttClient.Builder(client);
    final PahoObservableMqttClient target = builder.build();
    Assert.assertEquals(expectedClientId, target.getClientId());
}
 
开发者ID:patrickvankann,项目名称:rxmqtt,代码行数:10,代码来源:PahoObservableMqttClientTest.java

示例12: whenGetBrokerUriIsCalledItReturnsPahoServerUrl

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenGetBrokerUriIsCalledItReturnsPahoServerUrl() {
    final String expectedBrokerUri = "brokerUri";
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    Mockito.when(client.getServerURI()).thenReturn(expectedBrokerUri);
    final Builder builder = new PahoObservableMqttClient.Builder(client);
    final PahoObservableMqttClient target = builder.build();
    Assert.assertEquals(expectedBrokerUri, target.getBrokerUri());
}
 
开发者ID:patrickvankann,项目名称:rxmqtt,代码行数:10,代码来源:PahoObservableMqttClientTest.java

示例13: whenThePahoClientIsConnectedIsConnectedReturnsTrue

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenThePahoClientIsConnectedIsConnectedReturnsTrue() {
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    Mockito.when(client.isConnected()).thenReturn(true);
    final Builder builder = new PahoObservableMqttClient.Builder(client);
    final PahoObservableMqttClient target = builder.build();
    Assert.assertEquals(true, target.isConnected());
}
 
开发者ID:patrickvankann,项目名称:rxmqtt,代码行数:9,代码来源:PahoObservableMqttClientTest.java

示例14: whenCreateIsCalledThenAnObservableIsReturned

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledThenAnObservableIsReturned() throws Exception {
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    final MqttConnectOptions options = Mockito.mock(MqttConnectOptions.class);
    final ConnectFactory factory = new ConnectFactory(client, options);
    final ArgumentCaptor<IMqttActionListener> actionListener = ArgumentCaptor.forClass(IMqttActionListener.class);
    final Completable obs = factory.create();
    Assert.assertNotNull(obs);
    obs.subscribe();
    Mockito.verify(client).connect(Mockito.same(options), Mockito.isNull(),
            actionListener.capture());
    Assert.assertTrue(actionListener.getValue() instanceof ConnectFactory.ConnectActionListener);
}
 
开发者ID:patrickvankann,项目名称:rxmqtt,代码行数:14,代码来源:ConnectFactoryTest.java

示例15: whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled

import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; //导入依赖的package包/类
@Test
public void whenCreateIsCalledAndAnErrorOccursThenObserverOnErrorIsCalled() throws Throwable {
    expectedException.expectCause(isA(MqttException.class));
    final MqttConnectOptions options = Mockito.mock(MqttConnectOptions.class);
    final IMqttAsyncClient client = Mockito.mock(IMqttAsyncClient.class);
    Mockito.when(client.connect(Mockito.same(options), Mockito.isNull(),
            Mockito.any(ConnectFactory.ConnectActionListener.class)))
            .thenThrow(new MqttException(MqttException.REASON_CODE_CLIENT_CONNECTED));
    final ConnectFactory factory = new ConnectFactory(client, options);
    final Completable obs = factory.create();
    obs.blockingAwait();
}
 
开发者ID:patrickvankann,项目名称:rxmqtt,代码行数:13,代码来源:ConnectFactoryTest.java


注:本文中的org.eclipse.paho.client.mqttv3.IMqttAsyncClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。