Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Help with publishing
Help with publishing [message #1764155] Fri, 26 May 2017 02:46
Felipe Braz is currently offline Felipe BrazFriend
Messages: 1
Registered: May 2017
Junior Member
I'm new (and newbie) on development so I'm trying to learn and understand.

I'm using Eclipse Paho Java and I'm having some troubles with MqttClient and Publish.

I've created this class to be called by another methods to send messages:

import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;

public class mqttSend {

public void enviaMensagem(String content) {
String topic = "msgTratada";
String broker = "tcp://";
String clientId = "Servidor";

MqttClient client = new MqttClient(broker, clientId);
MqttConnectOptions conOpt = new MqttConnectOptions();

if(client.isConnected() == false){

MqttMessage message = new MqttMessage(content.getBytes());

client.publish(topic, message);

} catch(MqttException me) {
System.out.println("reason "+me.getReasonCode());
System.out.println("msg "+me.getMessage());
System.out.println("loc "+me.getLocalizedMessage());
System.out.println("cause "+me.getCause());
System.out.println("excep "+me);


My whole program works just fine, when I call this function the message is delivered and the program just closes. If I don't call it any time the program keeps working for hours, but in the moment I need to send a message it sends and close the all program.
What I did wrong?
My intention is having a method for calling every time I have to send a message, but the program needs to keep running and I should be able to send the amount of messages I want, anytime I want.

Could anyone help me?


Previous Topic:multiple publish not working
Next Topic:Client not connecting
Goto Forum:

Current Time: Wed Oct 21 11:21:51 GMT 2020

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

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

Back to the top