How to Subscribe to all topic form mqtt java client

Hi I have implemented Simple Mqtt Java Client I want that this client can subscribe to all topics.
I have implemented event bus for sending message
topic in event bus is like :-

How can I subscribe to all topics ?

at all for everything: #

This is getting me error like

Exception in thread “main” java.lang.IllegalArgumentException: The topic name MUST NOT contain any wildcard characters (#+)
at org.eclipse.paho.client.mqttv3.MqttTopic.validate(
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.getTopic(
at org.eclipse.paho.client.mqttv3.MqttClient.getTopic(
at mqttClient.mqttClient.JioSmartHomeMqttClient.runClient(
at mqttClient.mqttClient.JioSmartHomeMqttClient.main(

show the code where you are subscribing

package mqttClient.mqttClient;

import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttTopic;

public class JioSmartHomeMqttClient implements MqttCallback {

MqttClient mqttClient;
MqttConnectOptions connOpt;

static final String BROKER_URL = "tcp://localhost:1883";
// static final String M2MIO_DOMAIN = "<Insert domain here>";
static final String M2MIO_STUFF = "things";
static final String M2MIO_THING = "<Unique device ID>";
// static final String M2MIO_USERNAME = "< username>";
// static final String M2MIO_PASSWORD_MD5 = "< password (MD5 sum of
// password)>";

// the following two flags control whether this example is a publisher, a
// subscriber or both
static final Boolean subscriber = false;
static final Boolean publisher = false;

public void connectionLost(Throwable arg0) {
	// TODO Auto-generated method stub
	System.out.println("Connection Lost");


public void deliveryComplete(IMqttDeliveryToken arg0) {
	// TODO Auto-generated method stub
	System.out.println("Delivery Complete");


public void messageArrived(String arg0, MqttMessage arg1) throws Exception {
	// TODO Auto-generated method stub
	System.out.println("| Topic:" + arg0);
	System.out.println("| Message: " + new String(arg1.getPayload()));


public static void main(String[] args) {

	// TODO Auto-generated method stub
	JioSmartHomeMqttClient smc = new JioSmartHomeMqttClient();


 * runClient The main functionality of this simple example. Create a MQTT
 * client, connect to broker, pub/sub, disconnect.
public void runClient() {
	// setup MQTT Client
	String clientID = M2MIO_THING;
	connOpt = new MqttConnectOptions();

	// connOpt.setUserName(M2MIO_USERNAME);
	// connOpt.setPassword(M2MIO_PASSWORD_MD5.toCharArray());

	// Connect to Broker
	try {
		mqttClient = new MqttClient(BROKER_URL, clientID);

	} catch (MqttException e) {

	System.out.println("Connected to " + BROKER_URL);

	// setup topic
	// topics on are in the form <domain>/<stuff>/<thing>
	String myTopic = "#";
	MqttTopic topic = mqttClient.getTopic(myTopic);

	// subscribe to topic if subscriber
	if (subscriber) {
		try {
			int subQoS = 0;
			mqttClient.subscribe(topic.getName(), subQoS);
		} catch (Exception e) {

	// publish messages if publisher
	if (publisher) {
		for (int i = 1; i <= 10; i++) {
			String pubMsg = "{\"pubmsg\":" + i + "}";
			int pubQoS = 0;
			MqttMessage message = new MqttMessage(pubMsg.getBytes());

			// Publish the message
			// System.out.println("Publishing to topic \"" + topic + "\" qos " + pubQoS);
			MqttDeliveryToken token = null;
			try {
				// publish message to broker
				// token = topic.publish(message);
				// Wait until the message has been delivered to the broker
			} catch (Exception e) {

	// disconnect
	try {
		// wait to ensure subscribed messages are delivered
		if (subscriber) {
	} catch (Exception e) {


I am using ecliple paho library, In getTopic() method while valadating topic , allow wildcard characeters flag is fasle that is why I am getting this above error

MqttTopic	getTopic(java.lang.String topic)
Get a topic object which can be used to publish messages.

Are you sure you are signing and not publishing?
Do you have the same?

I am not publishing it, I am only Subscribing it.

note, it says here, is used for publication.
I’m not familiar with Java, the last thing I can recommend, try the following:

mqttClient.subscribe(myTopic, subQoS);