represents a channel receiver function that applies fun to any channel message it receives.
ChannelReceiverFunction
represents a channel receiver function that applies fun to any channel message it receives.
Details and Options
- CloudDeploy[ChannelReceiverFunction[…]] yields a CloudObject containing meta-information that specifies the channel to which messages for the channel receiver should be sent.
- CloudDeploy[ChannelReceiverFunction[…]"curi"] deploys the receiver to ChannelObject["curi"].
- CloudDeploy[ChannelReceiverFunction[…]channel] deploys the receiver to the specified channel, given as ChannelObject[…].
- CloudDeploy[ChannelReceiverFunction[…]] is equivalent to CloudDeploy[ChannelReceiverFunction[…]Automatic].
- In a deployed ChannelReceiverFunction[fun], fun[assoc] is evaluated whenever a channel message is received. The association assoc contains the same elements as in ChannelListen, except for ones specific to the ChannelListener object.
- CloudDeploy[ChannelReceiverFunction[fun]] sets up a channel receiver function that is executed in the cloud and does not require active listeners in any specific Wolfram Language session.
- The function fun is evaluated in the environment of the owner of the channel receiver function.
- Channel receiver functions cannot be triggered by messages that were themselves sent from within channel receiver functions.
Examples
open all close allBasic Examples (3)
f = ChannelReceiverFunction[{#Message, #MessageID}&]Apply the function to an association representing a channel broker message:
f[<|"Message" -> "message", "MessageID" -> "id"|>]Define a receiver function that logs the incoming message to a cloud object:
f = ChannelReceiverFunction[CloudPut[#Message, CloudObject[ "LastMessage"]]&]object = CloudDeploy[f]Obtain the target channel of the receiver:
channel = ChannelObject[object]Send a message to the channel:
ChannelSend[channel, "hello"]CloudGet[CloudObject["LastMessage"]]DeleteChannel[channel];
DeleteObject[object];Define a receiver function that logs the incoming message to a databin:
bin = CreateDatabin[];
f = ChannelReceiverFunction[DatabinAdd[bin, #]&]object = CloudDeploy[f]Obtain the target channel of the receiver function:
channel = ChannelObject[object]Send a message to the channel:
ChannelSend[channel, "hello"]Check the contents of the databin:
bin["Entries"]Timestamps are treated specially by the Wolfram Data Drop and are available in a separate property (or together with the entry body in the “FullEntries” property):
bin["Timestamps"]DeleteChannel[channel];
DeleteObject[{object, bin}];Scope (7)
ChannelReceiverFunction[#&][<|"Message" -> <|"a" -> "b"|>, "MessageID" -> "id"|>]Apply to a string representing a JSON object:
ChannelReceiverFunction[#Message&]["{\"x\":\"1\"}"]Deploy to an anonymous cloud object and anonymous channel object:
obj = CloudDeploy[ChannelReceiverFunction[#&]]ChannelObject[obj]DeleteChannel[%];
DeleteObject[obj];Deploy to the specified channel object:
obj = CloudDeploy[ChannelReceiverFunction[#&] -> "channel"]ChannelObject[obj]DeleteChannel[%];
DeleteObject[obj];Deploy to the specified cloud object:
obj = CloudDeploy[ChannelReceiverFunction[#&], "cloudObject"]ChannelObject[obj]DeleteChannel[%];
DeleteObject[obj];Deploy to the specified channel object and the specified cloud object:
obj = CloudDeploy[ChannelReceiverFunction[#&] -> "channel", "cloudObject"]ChannelObject[obj]DeleteChannel[%];
DeleteObject[obj];Specify the targets as objects:
obj = CloudDeploy[ChannelReceiverFunction[#&] -> ChannelObject["channel"], CloudObject["x"]]ChannelObject[obj]DeleteChannel[%];
DeleteObject[obj];Applications (3)
Deploy a channel that adds incoming messages to a databin:
bin = CreateDatabin[]obj = CloudDeploy[ChannelReceiverFunction[DatabinAdd[bin, <|"Data" -> #Message|>]&] -> "channel"]Send a message to the channel and retrieve its content from the databin:
ChannelSend["channel", "hello"]bin["Entries"]DeleteObject[{bin, obj}];
DeleteChannel["channel"];Define a receiver function that sends messages containing the string "URGENT" to a priority channel and the rest to a bulk channel:
f = ChannelReceiverFunction[ChannelSend[If[StringContainsQ[#Message, "URGENT"], "priority", "bulk"], #Message]&]Create the two channels and deploy the receiver function to a third channel, which is automatically created:
CreateChannel /@ {"priority", "bulk"}
obj = CloudDeploy[f -> "dispatcher"]Start listening on the channels:
priority = ChannelListen["priority"]bulk = ChannelListen["bulk"]Send a regular and an urgent message on the dispatcher channel:
Scan[ChannelSend["dispatcher", #]&, {"URGENT message", "low priority"}]priority["Message"]bulk["Message"]DeleteChannel[{"priority", "bulk", "dispatcher"}];
DeleteObject[obj];Deploy a receiver function that sends an email alert if a message arrives when nobody is listening on the channel:
channel = "withAlert";
CreateChannel[channel];obj = CloudDeploy[ChannelReceiverFunction[If[ChannelSubscribers[channel] === {}, SendMail[<|"To" -> $WolframID, "Subject" -> "missed message from " <> #RequesterWolframID, "Body" -> #Message|>]]&] -> channel]Send a message on the channel and check your mailbox for an email alert:
ChannelSend[channel, "Are you there?"]DeleteChannel[channel];
DeleteObject[obj];Properties & Relations (1)
Deploying ChannelReceiverFunction sets ChannelBrokerAction for the associated channel object:
CloudDeploy[ChannelReceiverFunction[#&]]Options[ChannelObject[%], ChannelBrokerAction]Related Guides
Text
Wolfram Research (2017), ChannelReceiverFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/ChannelReceiverFunction.html (updated 2020).
CMS
Wolfram Language. 2017. "ChannelReceiverFunction." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/ChannelReceiverFunction.html.
APA
Wolfram Language. (2017). ChannelReceiverFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ChannelReceiverFunction.html
BibTeX
@misc{reference.wolfram_2026_channelreceiverfunction, author="Wolfram Research", title="{ChannelReceiverFunction}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/ChannelReceiverFunction.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_channelreceiverfunction, organization={Wolfram Research}, title={ChannelReceiverFunction}, year={2020}, url={https://reference.wolfram.com/language/ref/ChannelReceiverFunction.html}, note=[Accessed: 13-June-2026]}