How to fix mosquitto mid values? - mosquitto

I use the mosquitto mqtt broker and have a question about its message id (mid) values as follows.
I send a message to test channel that has a mid of "1234", but the PUBACK mid is printed as another value
I want to print mid "1234"
What do I need to modify in the mosquitto source?
1435417408: Received PUBLISH from adventures (d0, q1, r0, m1234, 'test', ... (5 bytes))
1435417408: Sending PUBLISH to myclientid_49 (d0, q1, r0, m3, 'test', ... (5 bytes))
1435417408: Sending PUBLISH to myclientid_20 (d0, q1, r0, m2, 'test', ... (5 bytes))
1435417408: Sending PUBACK to adventures (Mid: 1234)
1435417408: Received DISCONNECT from adventures
1435417409: Received PUBACK from myclientid_49 (Mid: 3)
1435417409: Received PUBACK from myclientid_20 (Mid: 2)

Let me just go through your broker logs for you.
This line is your published message received from the adventures client. You can see m1234 which is saying that the message id is 1234, like you said.
1435417408: Received PUBLISH from adventures (d0, q1, r0, m1234, 'test', ... (5 bytes))
These two lines show the message being sent to two clients that are subscribed to the test topic. They have message id 3 and 2 respectively. Note that message ids are handled separately for different clients and message directions.
1435417408: Sending PUBLISH to myclientid_49 (d0, q1, r0, m3, 'test', ... (5 bytes))
1435417408: Sending PUBLISH to myclientid_20 (d0, q1, r0, m2, 'test', ... (5 bytes))
This is the broker sending the PUBACK back to the original client. You'll see again that the message id is 1234.
1435417408: Sending PUBACK to adventures (Mid: 1234)
This is the disconnect message from the original client.
1435417408: Received DISCONNECT from adventures
And this is the subscribing clients sending a PUBACK back to the broker, repeating the mid 3 and 2 from above.
1435417409: Received PUBACK from myclientid_49 (Mid: 3)
1435417409: Received PUBACK from myclientid_20 (Mid: 2)
In conclusion, I think it all makes sense.

Related

Unable to receive affiliation change notification from iq

I am using mod muc_light in MongooseIM from source code(ver-3.1.0) and taking help from this article I am able to perform the below operations successfully without any trouble:
create a new muc light room.
send/receive text message stanza
queries MAM and receives regular groupchat message. ['6.2.1 Groupchat message from occupant' from above article][Even, here I am getting the muc info but since this is related to a particular muc light room. So, not much useful.]
But I am unable to query MAM and receives an affiliation change notification. See topic [6.2.2 Affiliation change] in the above article link.
Following is the request/response for 'affiliation change notification'
// Request to server with type='set'
<iq type='set'
id='mamget2'
to='muclight.localhost'>
<query xmlns='urn:xmpp:mam:1' queryid='f37'/>
</iq>
// Response from server
<iq xmlns='jabber:client'
from='muclight.localhost'
to='ip0a0g0ur63vdjns#localhost/E42B7412598F3B081543-557985-559692'
id='mamget2'
type='error'>
<error code='' type='cancel'>
<not-allowed xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
<text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>The action is not allowed.</text>
</error>
</iq>
// Request to server with type='get'
<iq type='get'
id='mamget2'
to='muclight.localhost'>
<query xmlns='urn:xmpp:mam:1' queryid='f37'/>
</iq>
// Response from server
<iq xmlns='jabber:client'
from='muclight.localhost'
to='ip0a0g0ur63vdjns#localhost/E42B7412598F3B081543-557985-559692'
id='mamget2'
type='error'>
<error code='' type='cancel'>
<not-allowed xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
<text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>The action is not allowed.</text>
</error>
</iq>
MongooseIM config:
{mod_muc_light, [
{host, "muclight.#HOST#"},
{backend, rdbms},
{max_occupants, 256}
]},
{mod_mam_meta, [
{backend, rdbms},
{no_stanzaid_element, true},
{is_archivable_message, "muclight.#HOST#"},
{pm, false},
{muc, [
{host, "muclight.#HOST#"}
]}
]}
Questions/concerns:
Am I doing something wrong in config? - [I doubt this, because some others operation are working fine like mentioned above]
Am I sending the incorrect IQ stanza - [I doubt this because I am copying the exact same stanza example provided in above link]
Should I update MongooseIM. [May be]
Anything else?
Please help

FETCH command IMAP based on headers defined by RFC822

I have this command come from Thunderbird client email:
6 UID fetch 1 (UID RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (From To Cc Bcc Subject Date Message-ID Priority X-Priority References Newsgroups In-Reply-To Content-Type Reply-To)])
To respond it, I send the follows statements:
* 1 FETCH (UID 1 RFC822.SIZE 526 BODY[] {526}
* FLAGS (\Seen)
From: "Bob Smith" <bob#bar.com>
To: "John Smith" <john#foo.com>
Cc: "Joe Aaron" <joe#bar.com>
Subject: Sintaxe correta para criação de cabeçalhos de email
Date: 30 Jul 1996 11:54:54 -0000
Message-ID: <OTJMCQtXnqgMaP1rLJi-cD9IvuH+xuVndE-DoWAZB0cbdffqHdw#mail.gmail.com>
Reply-To: <bob#bar.com>
After this, Thunderbird client not send any command, and don't fetch nothing more and messages don't appear in mailbox.
In Thunderbird client the message "download message" start and never dropout
Is the first time that I study IMAP servers and I no have any idea how to proceed in this question.
Thanks;
Did you send the " OK FETCH completed" response? You must do that to signal command completion to the client.
Check the FETCH command section in the IMAP RFC. More specifically page 58 reveals an OK response example.

Mirth Connect HTTP Listener Mapping Response ACK message

We are trying to merge two Mirth servers. One server (let's call it Server 1) is keeping all records and another server (Server 2) is getting HL7 message from the first one and writes messages to the database.
Everything was perfect so far. But Server 1, after sending each HL7 message, waits for ACK to consider this transaction as completed and to send another message from the list.
The success status coming from the Server 2 (which writes to the database) contains MySQL response such as "Success: Database write success. 1 rows updated.". This is not what Server 1 is expecting.
Therefore, the Server 1 considers this ACK as invalid, produces an error "Message Read Error - Will Retry" and keeps trying to send the same message again, causing Server 2 to duplicate messages in the database.
We are using Mirth Connect HTTP listener and we could not find any solution to send ACK msg to our first server the same screen HTTP listener.
Is there any way to do this? Any Suggestion?
Really need help.
The problem is you are not setting the response from server 2 correctly, so it just returns what the destination has. You can create an ACK by code on the destination transformer:
var ackMessage = ACKGenerator.generateAckResponse(connectorMessage.getRawData(), "AA", "Message Successfully Received");
responseMap.put("ackresp", ResponseFactory.getSentResponse(ackMessage));
And on your source connector select "ackresp" as response. Your server 1 will receive that ACK instead of the log of the database write.

Erlang : Tcp Server

Hi I am a new bee in Erlang but managed to create a simple TCP server which accepts client in passive mode and displays message.
I spawn a new process every time new client connects to the server. Is there a way I could send message to the client using the process which gets spawned when client connects.
Here is code.
-module(test).
-export([startserver/0]).
startserver()->
{ok, ListenSocket}=gen_tcp:listen(1235,[binary,{active, false}]),
connect(ListenSocket).
connect(ListenSocket)->
{ok, UserSocket}=gen_tcp:accept(ListenSocket),
Pid=spawn(? MODULE, user,[UserSocket]),
gen_tcp:controlling_process(UserSocket, Pid),
connect(ListenSocket).
user(UserSocket)->
case gen_tcp:recv(UserSocket, 0) of.
{ok, Binary}->% Send basic message.
{error, closed}->% operation on close.
end.
Can I have some thing like if I do.
Pid!{"Some Message"}. And the message is send to the socket associated with the process with non blocking io,
You could try this tutorial for writing a TCP server using OTP principles: http://learnyousomeerlang.com/buckets-of-sockets#sockserv-revisited
If you use a gen_server instead of your connect loop, you can store the Pids in the state. Then you can use gen_server:cast/2 to send a message to one of the Pids.
The function you want to send a message to the client from the controlling process is gen_tcp:send(Socket, Message), so for example if you wanted to send a one off message on connection you could do this:
user(UserSocket)->
gen_tcp:send(UserSocket, "hello"),
case gen_tcp:recv(UserSocket, 0) of
{ok, Binary}->% Send basic message.
gen_tcp:send(UserSocket, "basic message"),
{error, closed}->% operation on close.
gen_tcp:send(UserSocket, "this socket is closing now"),
end.

Erlang spawn problems

I am having problem with 'spawn' in erlang, it seems processes just die after awhile. Here's the simple code:
-module(simple).
-export([server/1, client/1, owner/1, spawn_n/2, start/1, main/1]).
server(State) ->
receive
{request,Return_PID} ->
io:format("SERVER ~w: Client request recieved from ~w~n", [self(),Return_PID]),
NewState = State + 1,
Return_PID ! {hit_count,NewState},
server(NewState);
{server_owner,Owner_PID} ->
io:format("SERVER ~w: Owner request recieved from ~w~n", [self(), Owner_PID]),
Owner_PID ! {hit_count,State},
server(State);
reset ->
io:format("SERVER ~w: State reset to zero.~n", [self()]),
server(0)
end.
client(Server_Address) ->
Server_Address ! {request, self()},
receive
{hit_count,Number} ->
io:format("CLIENT ~w: Hit count was ~w~n", [self(),Number])
end.
owner(Server_PID) ->
timer:sleep(random:uniform(100)),
Server_PID ! {server_owner,self()},
receive
{hit_count,Number} when Number > 5 ->
io:format("OWNER: Hit count is ~w , reseting counter. ~n", [Number]),
Server_PID ! reset,
owner(Server_PID);
{hit_count,Number} when Number < 5 ->
io:format("OWNER ~w: Hit count was ~w~n", [self(), Number]),
owner(Server_PID)
end.
spawn_n(N, Server_PID) ->
if
N>0 ->
spawn(simple,client,[Server_PID]),
timer:sleep(random:uniform(100)),
spawn_n(N-1,Server_PID);
N==0 ->
io:format("Last client spawned. ~n")
end.
start(N) ->
Server_PID = spawn(simple,server,[0]),
spawn(simple,owner,[Server_PID]),
spawn(simple,spawn_n,[N,Server_PID]).
main([Arg]) ->
N = list_to_integer(atom_to_list(Arg)),
start(N),
init:stop().
Here's an example I get when running it:
erl -noshell -s simple main 20
SERVER <0.28.0>: Client request recieved from <0.31.0>
CLIENT <0.31.0>: Hit count was 1
SERVER <0.28.0>: Owner request recieved from <0.29.0>
SERVER <0.28.0>: Client request recieved from <0.32.0>
OWNER <0.29.0>: Hit count was 1
CLIENT <0.32.0>: Hit count was 2
SERVER <0.28.0>: Owner request recieved from <0.29.0>
SERVER <0.28.0>: Client request recieved from <0.33.0>
OWNER <0.29.0>: Hit count was 2
CLIENT <0.33.0>: Hit count was 3
SERVER <0.28.0>: Owner request recieved from <0.29.0>
SERVER <0.28.0>: Client request recieved from <0.34.0>
OWNER <0.29.0>: Hit count was 3
CLIENT <0.34.0>: Hit count was 4
SERVER <0.28.0>: Owner request recieved from <0.29.0>
SERVER <0.28.0>: Client request recieved from <0.35.0>
OWNER <0.29.0>: Hit count was 4
CLIENT <0.35.0>: Hit count was 5
SERVER <0.28.0>: Owner request recieved from <0.29.0>
SERVER <0.28.0>: Client request recieved from <0.36.0>
CLIENT <0.36.0>: Hit count was 6
SERVER <0.28.0>: Client request recieved from <0.37.0>
CLIENT <0.37.0>: Hit count was 7
SERVER <0.28.0>: Client request recieved from <0.38.0>
CLIENT <0.38.0>: Hit count was 8
SERVER <0.28.0>: Client request recieved from <0.39.0>
CLIENT <0.39.0>: Hit count was 9
SERVER <0.28.0>: Client request recieved from <0.40.0>
CLIENT <0.40.0>: Hit count was 10
SERVER <0.28.0>: Client request recieved from <0.41.0>
CLIENT <0.41.0>: Hit count was 11
SERVER <0.28.0>: Client request recieved from <0.42.0>
CLIENT <0.42.0>: Hit count was 12
SERVER <0.28.0>: Client request recieved from <0.43.0>
CLIENT <0.43.0>: Hit count was 13
SERVER <0.28.0>: Client request recieved from <0.44.0>
CLIENT <0.44.0>: Hit count was 14
SERVER <0.28.0>: Client request recieved from <0.45.0>
CLIENT <0.45.0>: Hit count was 15
SERVER <0.28.0>: Client request recieved from <0.46.0>
CLIENT <0.46.0>: Hit count was 16
SERVER <0.28.0>: Client request recieved from <0.47.0>
CLIENT <0.47.0>: Hit count was 17
SERVER <0.28.0>: Client request recieved from <0.48.0>
CLIENT <0.48.0>: Hit count was 18
{error_logger,{{2011,6,27},{12,57,8}},"~s~n",["Error in process <0.28.0> with ex
it value: {terminated,[{io,format,[<0.22.0>,\"SERVER ~w: Client request recieved
from ~w~n\",[<0.28.0>,<0.49.0>]]},{simple,server,1}]}\n"]}
I don't get it. The processes just die or something? It shouldnt terminate!
I am running on windows 7 if it might be something windows-related.
Thanks
EDIT: heres what happens by doing application:start(sasl). before:
C:\Program Files\erl5.8.4\bin>erl
Eshell V5.8.4 (abort with ^G)
1> application:start(sasl).
ok
=PROGRESS REPORT==== 27-Jun-2011::16:03:55 ===
supervisor: {local,sasl_safe_sup}
started: [{pid,<0.37.0>},
{name,alarm_handler},
{mfargs,{alarm_handler,start_link,[]}},
{restart_type,permanent},
{shutdown,2000},
{child_type,worker}]
2>
=PROGRESS REPORT==== 27-Jun-2011::16:03:55 ===
supervisor: {local,sasl_safe_sup}
started: [{pid,<0.38.0>},
{name,overload},
{mfargs,{overload,start_link,[]}},
{restart_type,permanent},
{shutdown,2000},
{child_type,worker}]
2>
=PROGRESS REPORT==== 27-Jun-2011::16:03:55 ===
supervisor: {local,sasl_sup}
started: [{pid,<0.36.0>},
{name,sasl_safe_sup},
{mfargs,
{supervisor,start_link,
[{local,sasl_safe_sup},sasl,safe
{restart_type,permanent},
{shutdown,infinity},
{child_type,supervisor}]
2>
=PROGRESS REPORT==== 27-Jun-2011::16:03:55 ===
supervisor: {local,sasl_sup}
started: [{pid,<0.39.0>},
{name,release_handler},
{mfargs,{release_handler,start_link,[]}}
{restart_type,permanent},
{shutdown,2000},
{child_type,worker}]
2>
=PROGRESS REPORT==== 27-Jun-2011::16:03:55 ===
application: sasl
started_at: nonode#nohost
2> simple:main(['20']).
ok
SERVER <0.42.0>: Client request recieved from <0.45.0>
3> CLIENT <0.45.0>: Hit count was 1
3> SERVER <0.42.0>: Owner request recieved from <0.43.0>
3> SERVER <0.42.0>: Client request recieved from <0.47.0>
3> OWNER <0.43.0>: Hit count was 1
3> CLIENT <0.47.0>: Hit count was 2
3> SERVER <0.42.0>: Owner request recieved from <0.43.0>
3> SERVER <0.42.0>: Client request recieved from <0.48.0>
3> OWNER <0.43.0>: Hit count was 2
3> CLIENT <0.48.0>: Hit count was 3
3> SERVER <0.42.0>: Owner request recieved from <0.43.0>
3> SERVER <0.42.0>: Client request recieved from <0.49.0>
3> OWNER <0.43.0>: Hit count was 3
3> CLIENT <0.49.0>: Hit count was 4
3> SERVER <0.42.0>: Owner request recieved from <0.43.0>
3> SERVER <0.42.0>: Client request recieved from <0.50.0>
3> OWNER <0.43.0>: Hit count was 4
3> CLIENT <0.50.0>: Hit count was 5
3> SERVER <0.42.0>: Owner request recieved from <0.43.0>
3> SERVER <0.42.0>: Client request recieved from <0.51.0>
3> CLIENT <0.51.0>: Hit count was 6
3> SERVER <0.42.0>: Client request recieved from <0.52.0>
3> CLIENT <0.52.0>: Hit count was 7
3> SERVER <0.42.0>: Client request recieved from <0.53.0>
3> CLIENT <0.53.0>: Hit count was 8
3> SERVER <0.42.0>: Client request recieved from <0.54.0>
3> CLIENT <0.54.0>: Hit count was 9
3> SERVER <0.42.0>: Client request recieved from <0.55.0>
3> CLIENT <0.55.0>: Hit count was 10
3> SERVER <0.42.0>: Client request recieved from <0.56.0>
3> CLIENT <0.56.0>: Hit count was 11
3> SERVER <0.42.0>: Client request recieved from <0.57.0>
3> CLIENT <0.57.0>: Hit count was 12
3> SERVER <0.42.0>: Client request recieved from <0.58.0>
3> CLIENT <0.58.0>: Hit count was 13
3> SERVER <0.42.0>: Client request recieved from <0.59.0>
3> CLIENT <0.59.0>: Hit count was 14
3> SERVER <0.42.0>: Client request recieved from <0.60.0>
3> CLIENT <0.60.0>: Hit count was 15
3> SERVER <0.42.0>: Client request recieved from <0.61.0>
3> CLIENT <0.61.0>: Hit count was 16
3> SERVER <0.42.0>: Client request recieved from <0.62.0>
3> CLIENT <0.62.0>: Hit count was 17
3> SERVER <0.42.0>: Client request recieved from <0.63.0>
3> CLIENT <0.63.0>: Hit count was 18
3> {error_logger,{{2011,6,27},{16,3,58}},"~s~n",["Error in proc
exit value: {terminated,[{io,format,[<0.23.0>,\"SERVER ~w: Cli
ved from ~w~n\",[<0.42.0>,<0.64.0>]]},{simple,server,1}]}\n"]}
The other answer is correct, but it doesn't explain why.
It's a tricky question, and the answer is (sort of) in your log output:
{error_logger,{{2011,6,27},{12,57,8}},"~s~n",["Error in process <0.28.0> with exit value: {terminated,[{io,format,[<0.22.0>,\"SERVER ~w: Client request recieved from ~w~n\",[<0.28.0>,<0.49.0>]]},{simple,server,1}]}\n"]}
The first clue is that io:format/3 exits with 'terminated' and some data.
Looking at the documentation and searching for terminated gives ... nothing. Looking inside io.erl gives us the answer though.
Line 456 and 462 of io.erl returns {error, terminated} when the io device is down. So now we know that io:format can potentially exit with status terminated. Looking further we can see that this return value turns into the above error message on line 74 (with context):
case request(Io, Request) of
{error, Reason} ->
[_Name | Args] = tuple_to_list(to_tuple(Request)),
{'EXIT',{undef,[_Current|Mfas]}} = (catch erlang:error(undef)),
MFA = {io, Func, [Io | Args]},
exit({conv_reason(Func, Reason),[MFA|Mfas]});
If you follow the call path for request/2 you will find that one possible branch is at the {error, terminated} mentioned earlier.
So, long story short, standard out is down.
Most likely since you killed your system with init:stop().
You are calling init:stop() immediately after your spawns. How are you going to make sure all your processes are properly finished? You probably need to block on receive in main and notify main process when others are done.

Resources