ChannelListen
ChannelListen[channel]
starts listening on the specified channel.
ChannelListen[channel,func]
applies func to the association corresponding to each message received on the channel.
ChannelListen[channel,None]
stores each message received on the channel, without applying any function.
ChannelListen[url]
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.
Examples
open allclose allBasic Examples (2)
Create a channel and start listening:
Send a message to the channel and retrieve the contents of the message from the listener:
Remove the listener and delete the channel:
Define a custom handler function that will be executed when a message arrives:
Sending a message to the channel causes the function to be called:
The message is also recorded in the ChannelListener object:
Scope (4)
Channel Specifications (2)
Listen on a channel defined by a ChannelObject:
Listen on a channel in your home area on the channel broker server, specifying its name:
Listen on a channel specified by its fully qualified name:
Listen on a channel specified by its full URL:
Delete the channel, which removes the listener:
Listen on a channel in the common area on the server, specified by a URL:
Handlers (2)
Examine the arguments received by the handler function:
Sending a message to the channel prints the association received by the handler:
Delete the channel, which removes the listener:
Do not execute any handler function when messages are received:
Options (3)
AutoRemove (1)
ChannelHistoryLength (1)
Create a channel listener with ChannelHistoryLength set to 10:
Send 20 messages to the channel:
Applications (4)
Email (1)
In a desktop session, set up a listener that speaks the subject of an incoming message:
Create a MailReceiverFunction that forwards received mail to your listener:
Send an email to the receiver function and hear your listener speak:
Remote Evaluation (1)
In your Wolfram Cloud account, or any other remote Wolfram System, set up a listener that evaluates incoming messages and sends the result back to a specified channel:
Set up a receiving channel on your local system:
Send a command to the remote evaluator:
Wolfram Cloud (1)
ChannelListen allows your current session to receive updates from APIFunction, FormFunction and other functions as they are executed in the Wolfram Cloud:
Deploy a webpage that performs a simple operation and sends the result along with some metadata to the listener:
The listener dynamically updates as soon as the web form is submitted:
Social Media (1)
Create an APIFunction that forwards the contents of HTTP requests to a channel:
Create an IFTTT applet that tracks mentions of the word "Mathematica" on Twitter and sends them to the APIFunction via HTTP:
Create a listener on the channel:
Create a service connection to Twitter and send a tweet containing the keyword:
Properties & Relations (3)
ChannelListen returns a ChannelListener object:
You can query the listener and retrieve its properties:
Delete the channel, which removes the listener:
Use RemoveChannelListener to remove a ChannelListener object:
On desktop Wolfram systems, output of Print executed in the message handler function is directed to the Messages window:
Possible Issues (1)
Text
Wolfram Research (2016), ChannelListen, Wolfram Language function, https://reference.wolfram.com/language/ref/ChannelListen.html (updated 2020).
CMS
Wolfram Language. 2016. "ChannelListen." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/ChannelListen.html.
APA
Wolfram Language. (2016). ChannelListen. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ChannelListen.html