1

I'm trying to set create the client first to test that the MQTT works without errors then I will implement the connect() method. I downloaded the latest version of HiveMQ (an open source MQTT implementation done in Java) and after importing the project properly as a Gradle build in Eclipse and using GIT I was greeted with an error message. It said "DaggerSingletonComponent cannot be resolved." My program can't run at all.

Link to the open source I downloaded: https://github.com/hivemq/hivemq-mqtt-client

I've tried manually editing the build files to see if there was some code left out for dagger in dependencies but there wasn't.

package com.hivemq.client.internal.mqtt.ioc;

import com.hivemq.client.internal.mqtt.netty.NettyEventLoopProvider;
import com.hivemq.client.internal.mqtt.netty.NettyModule;
import dagger.Component;
import org.jetbrains.annotations.NotNull;

import javax.inject.Singleton;

/**
 * Singleton component for all clients. It exists the whole application lifetime.
 *
 * @author Silvio Giebl
 */
@Component(modules = {NettyModule.class})
@Singleton  
public interface SingletonComponent {

    @NotNull SingletonComponent INSTANCE = DaggerSingletonComponent.create();

    @NotNull ClientComponent.Builder clientComponentBuilder();

    @NotNull NettyEventLoopProvider nettyEventLoopProvider();
}


__________________________
For the module: NettyModule.class


package com.hivemq.client.internal.mqtt.netty;

import dagger.Module;

import dagger.Provides;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollSocketChannel;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.jetbrains.annotations.NotNull;

import javax.inject.Singleton;

/**
 * @author Silvio Giebl
 */
@Module
public abstract class NettyModule {

    @Provides
    @Singleton
    static @NotNull NettyEventLoopProvider provideNettyEventLoopProvider() {
        if (Epoll.isAvailable()) {
            return new NettyEventLoopProvider(EpollEventLoopGroup::new, EpollSocketChannel::new);
        } else {
            return new NettyEventLoopProvider(NioEventLoopGroup::new, NioSocketChannel::new);
        }
    }
}

Error Message: DaggerSingletonComponent cannot be resolved

Chigozie A.
  • 335
  • 4
  • 16
  • 1
    I think you just want to use the client. Then you should include the library as a maven dependency (https://hivemq.github.io/hivemq-mqtt-client/docs/installation.html) in your own project. You only have to check out the source if you want to contribute to the project. – SgtSilvio Jun 05 '19 at 08:37
  • I actually want to use both the HiveMQ client and the HiveMQ community edition broker. I need to be able to create an MQTT communication and be able to modify both freely and eventually adding other things like AES encryption as needed. I was able to import the community edition broker successfully without any issues but I still need to figure out how to run it properly. I think I'm missing something like running/moving an executable file. This is the link to the open source broker I downloaded: https://github.com/hivemq/hivemq-community-edition. – Chigozie A. Jun 05 '19 at 13:59
  • @SgtSilvio Maybe I should add the client as a dependency to the HiveMQ open source broker? I don't plan on contributing, I only want to use the client libraries. – Chigozie A. Jun 05 '19 at 14:28
  • 1
    I think you should have a separate project for your client application that includes the library as a maven dependency. It does not make a lot of sense to have broker and clients in the same application. – SgtSilvio Jun 11 '19 at 09:25

1 Answers1

3

Dagger is a library that generates code for dependency injection at compile time. The mentioned class is one of the generated classes.

Please use gradle to build the project:

  1. Open a terminal
  2. Navigate to the project directory
  3. Execute ./gradlew build (Linux/Mac) or gradlew build (Windows)

You need to ensure that the directory build/generated/source/apt/main/ is configured as a source directory so that the IDE picks up the generated classes.

Then you should be able to use the build methods of your IDE after the first build with gradle.

SgtSilvio
  • 476
  • 2
  • 5
  • I added build/generated/source/apt/main/ as a source directory and it was able to pick it up and I'm no longer getting those errors. But now when I tried to run my build it failed at 83% and failed 2 test which were in the package: com.hivemq.client.internal.mqtt.handler.ssl . It also mentions: Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0. Use '--warning-mode all' to show the individual deprecation warnings. Should I change these old Gradle features? Should I ignore those tests and deal with them later? – Chigozie A. Jun 05 '19 at 13:41
  • Which java version are you using? My guess would be Java 11+. Probably the tests use some ciphers that are not supported anymore. I will check this later. – SgtSilvio Jun 06 '19 at 15:37
  • I'm using Java version 11.0.3. I ignored those 2 test for now and my client works with the community edition server but I'll definitely look into those errors later. – Chigozie A. Jun 06 '19 at 15:47