starts listening on the specified channel.
applies func to the association corresponding to each message received on the channel.
stores each message received on the channel, without applying any function.
listens on the specified URL, storing messages received, without requiring an explicit channel to exist on the channel broker.
Details and Options
- ChannelListen[…] gives a ChannelListener object.
- In ChannelListen[channel,…], channel can be specified as a channel object or in any of the forms used inside ChannelObject.
- ChannelListen[channel] is equivalent to ChannelListen[channel,Automatic].
- If specified in ChannelListen[channel,func], func overrides the "MessageReceived" handler of channel. It is called with the association containing the following elements:
"Message" contents of the message "MessageID" unique message ID "Timestamp" server timestamp for the message "RequesterWolframID" Wolfram ID of the sender "RequesterWolframUUID" Wolfram UUID of the sender "ListenerID" ID of the current listener
- The contents of a message are given literally if the message is a string, Real, Integer, ByteArray, True, False, Null, Image or Image3D, or a list or association of such objects. All other messages are given either in the form HoldComplete[DisableFormatting[expr]] or as a list or association of delayed rules of the form "name"DisableFormatting[val].
- For security reasons, you should exercise caution in accessing unevaluated message contents, such as parts of held expressions, right-hand sides of delayed rules, or applying ToExpression to string messages.
- ChannelListen accepts the following options:
AutoRemove False whether to remove the listener after receiving one message ChannelBase $ChannelBase default channel base to assume ChannelHistoryLength 100 how many messages to store in the listener cache NotificationFunction Inherited notification to give when a message arrives
- A channel listener set up by ChannelListen can be removed using RemoveChannelListener.
- Removing a channel listener discards messages cached by the listener.
- Terminating a Wolfram Language session removes all active channel listeners.
Examplesopen allclose all
Basic Examples (2)
The message is also recorded in the ChannelListener object:
Channel Specifications (2)
Listen on a channel defined by a ChannelObject:
Create a channel listener with ChannelHistoryLength set to 10:
Create a MailReceiverFunction that forwards received mail to your listener:
Remote Evaluation (1)
Wolfram Cloud (1)
Social Media (1)
Create an APIFunction that forwards the contents of HTTP requests to a channel:
Properties & Relations (3)
On desktop Wolfram systems, output of Print executed in the message handler function is directed to the Messages window: