org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory Java Examples

The following examples show how to use org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MqttAutoConfiguration.java    From mqtt-spring-boot with MIT License 6 votes vote down vote up
@Bean
public DefaultMqttPahoClientFactory clientFactory() {

    MqttConnectOptions connectOptions = new MqttConnectOptions();
    String username = mqttProperties.getUsername();
    String password = mqttProperties.getPassword();
    if(username != null) {
        connectOptions.setUserName(username);
    }
    if (password != null) {
        connectOptions.setPassword(password.toCharArray());
    }
    String[] serverURIs = mqttProperties.getServerURIs();
    if (serverURIs == null || serverURIs.length == 0) {
        throw new NullPointerException("serverURIs can not be null");
    }
    connectOptions.setCleanSession(mqttProperties.getCleanSession());
    connectOptions.setKeepAliveInterval(mqttProperties.getKeepAliveInterval());
    connectOptions.setServerURIs(serverURIs);

    DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
    factory.setConnectionOptions(connectOptions);

    return factory;
}
 
Example #2
Source File: MqttConfiguration.java    From mqtt with Apache License 2.0 6 votes vote down vote up
@Bean
public MqttPahoClientFactory mqttClientFactory() {
	DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
	factory.setServerURIs(mqttProperties.getUrl());
	factory.setUserName(mqttProperties.getUsername());
	factory.setPassword(mqttProperties.getPassword());
	factory.setCleanSession(mqttProperties.isCleanSession());
	factory.setConnectionTimeout(mqttProperties.getConnectionTimeout());
	factory.setKeepAliveInterval(mqttProperties.getKeepAliveInterval());
	if (ObjectUtils.nullSafeEquals(mqttProperties.getPersistence(), "file")) {
		factory.setPersistence(new MqttDefaultFilePersistence(mqttProperties.getPersistenceDirectory()));
	}
	else if (ObjectUtils.nullSafeEquals(mqttProperties.getPersistence(), "memory")) {
		factory.setPersistence(new MemoryPersistence());
	}
	return factory;
}
 
Example #3
Source File: MqttTestSupport.java    From mqtt with Apache License 2.0 5 votes vote down vote up
@Override
protected void obtainResource() throws Exception {
	DefaultMqttPahoClientFactory connectionFactory = new DefaultMqttPahoClientFactory();
	connectionFactory.setServerURIs("tcp://localhost:1883");
	connectionFactory.setUserName("guest");
	connectionFactory.setPassword("guest");
	connectionFactory.setConnectionTimeout(1);
	resource = connectionFactory.getClientInstance("tcp://localhost:1883", "scdf-test-client");
	resource.connect(connectionFactory.getConnectionOptions());
}
 
Example #4
Source File: MqttConfig.java    From iot-dc3 with Apache License 2.0 4 votes vote down vote up
@Bean
public MqttPahoClientFactory mqttClientFactory() {
    DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
    factory.setConnectionOptions(getMqttConnectOptions());
    return factory;
}