Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » How correct method for test my mqtt client with Junit 5?
How correct method for test my mqtt client with Junit 5? [message #1823505] Fri, 27 March 2020 17:24
giuseppe ventura is currently offline giuseppe venturaFriend
Messages: 1
Registered: March 2020
Junior Member
I have doing a mqtt client with MqttPaho and work correctly,
I read from a topic and write in another topic.

Now I want test it with Junit5.. I don't understand well guide in internet (mockito??, moquette?).. in particular how mock producer or consumer.. I use configuration for consumer and producer class for example:
public class Consumer {
@Autowired MqttPahoClientFactory mqttClientFactory;
public MessageChannel topicChannel(){
    return new DirectChannel();

public MessageProducer mqttInbound() {
    MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(
            Parameters.MQTT_CLIENT_ID, mqttClientFactory, Parameters.TOPICS[0]);
    adapter.setConverter(new DefaultPahoMessageConverter());
    return adapter;

public class Producer {
    @Autowired MqttPahoClientFactory mqttClientFactory;
    public MessageChannel mqttOutboundChannel(){
        return new DirectChannel();
    @MessagingGateway(defaultRequestChannel = "mqttOutboundChannel")
    public interface ProducerGateway {
        void sendToMqtt(String data, @Header(MqttHeaders.TOPIC) String topic);
    @ServiceActivator(inputChannel = "mqttOutboundChannel")
    public MessageHandler mqttOutbound() {
        MqttPahoMessageHandler messageHandler = new MqttPahoMessageHandler(
        return messageHandler;

public class MqttConfiguration {

    public MqttPahoClientFactory mqttClientFactory() {
        DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
        MqttConnectOptions options = new MqttConnectOptions();
        return factory;


I want test

Read on topic1,
write on topic2,
Test if broker is runner,
Test if topic1/topic2 exist..
There is a little example just for learn?

thanks in advance

Previous Topic:mqtts protocol?
Next Topic:On expire of MQTT message using Python paho library.
Goto Forum:

Current Time: Fri Oct 23 03:36:59 GMT 2020

Powered by FUDForum. Page generated in 0.01762 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top