Callback interface to receive incoming messages.
Description
The IMessageReceive interface is used to receive incoming messages.
Methods
ReceiveMessage
Receives an incoming message from the queue.
See also MessageEnvelope, IMessageQueue
ReceiveMessage(ctx context.Context, envelope *MessageEnvelope, queue IMessageQueue) (err error)
- ctx: context.Context - operation context.
- envelope: *MessageEnvelope - incoming message,
- queue: IMessageQueue - queue where the message comes from.
- returns: (err error) - error or nil no errors occured.
Examples
type MyMessageReceiver struct {
func (c*MyMessageReceiver) ReceiveMessage(ctx context.Context, envelop MessageEnvelop, queue IMessageQueue) {
fmt.Println("Received message: " + envelop.GetMessageAsString())
}
}
messageQueue := NewMemoryMessageQueue()
messageQueue.Listen("123", NewMyMessageReceiver())
opnErr := messageQueue.Open("123")
if opnErr == nil{
messageQueue.Send("123", NewMessageEnvelope("", "mymessage", "ABC")) // Output in console: "Received message: ABC"
}