Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions NatsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,27 @@ public void Unsubscribe(int sid)
}
}

public bool Publish(string topic, string message)
public bool Publish(string topic, string message, string reply = "")
{
ThrowIfDisposed();
lock (stateLock)
{
return WhenConnected((conn) => SendPublish(conn, topic, message));
return WhenConnected((conn) => SendPublish(conn, topic, message, reply));
}
}

public int Request(string topic, string message, Action<string, string> handler)
{
ThrowIfDisposed();
string inbox = Guid.NewGuid().ToString("N");
var sid = this.Subscribe(inbox, (msg, reply) =>
{
handler(msg, reply);
});
this.Publish(topic, message, inbox);
return sid;
}

private void BuildConnectMsg(Uri natsUrl)
{
string user = null, pass = null;
Expand Down Expand Up @@ -353,9 +365,9 @@ private void SendUnsubscribe(Connection conn, long sid)
conn.Send("UNSUB " + sid + " 0");
}

private void SendPublish(Connection conn, string topic, string message)
private void SendPublish(Connection conn, string topic, string message, string reply)
{
conn.Send(new string[]{ "PUB " + topic + " " + message.Length, message });
conn.Send(new string[] { "PUB " + topic + " " + reply + " " + message.Length, message });
}

private void Processing()
Expand Down