Class LoopbackTransport
One in-process link to a broker.
public sealed class LoopbackTransport : ILink, IDisposable
- Inheritance
-
LoopbackTransport
- Implements
- Inherited Members
Remarks
Calls on one link run one at a time, so a send made while a receive is waiting runs once the receive returns. A task that listens should have a link of its own.
Methods
ConnectAsync()
Marks this link connected so it will carry traffic.
public Task ConnectAsync()
Returns
Remarks
A link that was disconnected keeps its subscriptions when it connects again.
Exceptions
- PamojaException
The native call failed.
DisconnectAsync()
Marks this link disconnected, so sends over it fail.
public Task DisconnectAsync()
Returns
Remarks
Messages queued for it are dropped; its subscriptions are kept.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
IsConnectedAsync()
Reports whether this link is connected.
public Task<bool> IsConnectedAsync()
Returns
ReceiveAsync()
Waits for the next message on a subscribed topic.
public Task<TransportMessage?> ReceiveAsync()
Returns
- Task<TransportMessage>
The message.
Remarks
A connected link never ends on its own, so this waits until a message arrives. Use ReceiveAsync(TimeSpan) to stop waiting.
Exceptions
- PamojaException
The link is not connected.
ReceiveAsync(TimeSpan)
Waits a limited time for the next message on a subscribed topic.
public Task<TransportMessage?> ReceiveAsync(TimeSpan timeout)
Parameters
timeoutTimeSpanHow long to wait.
Returns
- Task<TransportMessage>
The message.
Remarks
When the time runs out nothing is lost: a message arriving afterwards waits for the next receive.
Exceptions
- TimeoutException
No message arrived in time.
- PamojaException
The link is not connected.
SendAsync(string, ReadOnlyMemory<byte>)
Publishes a payload to a topic on the broker.
public Task SendAsync(string topic, ReadOnlyMemory<byte> payload)
Parameters
topicstringThe destination topic.
payloadReadOnlyMemory<byte>The bytes to publish.
Returns
Exceptions
- PamojaException
The link is not connected.
SendAsync(string, string)
Publishes text to a topic on the broker: words, or a number written out.
public Task SendAsync(string topic, string text)
Parameters
Returns
Exceptions
- PamojaException
The link is not connected.
SubscribeAsync(string)
Subscribes this link to a topic.
public Task SubscribeAsync(string topic)
Parameters
topicstringThe topic to subscribe to.
Returns
Exceptions
- PamojaException
The link is not connected.