B4J Library MqttBroker

Status
Not open for further replies.
jMqttBroker library is based on the moquette open source project: https://github.com/andsel/moquette

It implements a MQTT broker. If you are not familiar with MQTT then start with this tutorial: https://www.b4x.com/android/forum/threads/59471/#content

The broker is like a "black box". It is responsible for managing the clients and routing the messages.

With this library you can embed the broker inside your app instead of using an external broker.

Note that this library can also be used with B4A. You can turn any Android or Linux board to a MQTT broker.
With B4A you need to add the INTERNET permission with the manifest editor:
B4X:
AddPermission(android.permission.INTERNET)

Using this library is simple:
B4X:
Sub Process_Globals
   Dim broker As MqttBroker
End Sub

Sub AppStart (Args() As String)
   broker.Initialize("", 51041) 'first parameter is the event name. It is currently not used.
   broker.DebugLog = True
   broker.Start
   StartMessageLoop 'Non-UI app
End Sub

jMQTTBroker V1: www.b4x.com/b4j/files/moqueutte.zip

jMQTTBroker v2 based on moquette v0.12 (December 2018) is available here: www.b4x.com/b4j/files/jMqttBroker2.zip
Unlike v1, the new version is not compatible with B4A.

Updates:

V2.02 - Fixes a compatibility issue with B4JPackager 11.
V2.01 - Changes an internal auto-flush timeout that caused delays.
 
Last edited:

woniol

Active Member
Licensed User
Longtime User
Hi,
I tried it with jMQTT client, and every time i publish a message from the client i get this in the server logs:
B4X:
Serious error processing the message org.eclipse.moquette.proto.messages.PubAckMessage@58121280 for session [clientID: fsdfsdf]org.eclipse.moquette.server.netty.NettyChannel@3ad9b9ea

Is it normal, or am I doing something wrong?
 

woniol

Active Member
Licensed User
Longtime User
What's the problem with QOS 1 and QOS 2, can't we use it with b4j broker?
 

woniol

Active Member
Licensed User
Longtime User
One more thing,
although i set credentials on for the broker with
B4X:
broker.SetUserAndPassword("user","pass")
I can connect to it with
B4X:
client.Connect
When I use
B4X:
client.Connect2(MqttConnectOptions)
, credentials are veryfied.
 

woniol

Active Member
Licensed User
Longtime User
Credentials work fine now, thanks for the fix.

Here is a short example of the problems with setting QOS.
It looks like it has something to do with Subscribe QOS, try to change it to 1 or 2

In all Subscribe QOS settings, when i publish a message with QOS2 it is published with payload lenght = 0 (see the example)
 

Attachments

  • mqtt_qos_test.zip
    1.1 KB · Views: 1,455

fishwolf

Well-Known Member
Licensed User
Longtime User
jMqttBroker library is based on the moquette open source project: https://github.com/andsel/moquette

It implements a MQTT broker. If you are not familiar with MQTT then start with this tutorial: https://www.b4x.com/android/forum/threads/59471/#content

The broker is like a "black box". It is responsible for managing the clients and routing the messages.

With this library you can embed the broker inside your app instead of using an external broker.

Note that this library can also be used with B4A. You can turn any Android or Linux board to a MQTT broker.

Using this library is simple:
B4X:
Sub Process_Globals
   Dim broker As MqttBroker
End Sub

Sub AppStart (Args() As String)
   broker.Initialize("", 51041) 'first parameter is the event name. It is currently not used.
   broker.Start
   StartMessageLoop 'Non-UI app
End Sub

Download link: www.b4x.com/b4j/files/moqueutte.zip

I have done a No-UI application B4J with broken library and 3 lines of code.

I'm try to use the B4A chat example and the connection failed.

any suggestion?
 
Status
Not open for further replies.

Similar Threads

Top