# \[project\] SimpleMessaging: cascading message delivery

**URL:** <https://forum.inductiveautomation.com/t/project-simplemessaging-cascading-message-delivery/15566>\
**Category:** Ignition\
**Created:** [October 4, 2017, 12:54pm UTC](https://forum.inductiveautomation.com/t/project-simplemessaging-cascading-message-delivery/15566 "2017-10-04T12:54:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [October 4, 2017, 12:54pm UTC](https://forum.inductiveautomation.com/t/project-simplemessaging-cascading-message-delivery/15566/1 "2017-10-04T12:54:26Z")

</div>

This project simplifies component to component interaction through system.util.sendMessage. This approach is used in [Unity3D](https://docs.unity3d.com/ScriptReference/Component.SendMessage.html) and is helpful.

**How to Send Message**

```auto
    shared.simplemessaging.client.send("TOAST", { "message": "hello world", "severity": 7<a class="attachment" href="//cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/inductiveautomation/original/2X/1/1b45e1133f2823d8916b7b02f76ffab37d6712d7.proj">SimpleMessaging_2017-10-04_0732_partial.proj</a> (2.9 KB)
 })

```

The first argument is the message type. The receiving method name will include the message type in its name.  
The second argument is a message as a dictionary. The contents are up to your implementation but it must be a dictionary.

**How to Receive Message**  
Your project needs a Client Message Handler named ‘OnSimpleMessage’. The script of the handler is:

```auto
    shared.simplemessaging.client.onClientMessageReceived(payload)

```

In order for someone to receive the sent message we need to create a custom method on any one of our components in the component hierarchy. The format of the custom method name is ‘OnMessage\_{message-type}’. For the above example, the method name will be ‘OnMessage\_TOAST’ with a single argument of \*\*kwargs. Inside the receiving script you can access your message like so:

```auto
def OnMessage_TOAST(**kwargs):
    if kwargs is not None:
		for key, value in kwargs.iteritems():
			print "%s == %s" %(key,value)    

    isRemoteSource = False if system.util.getClientId()==kwargs["payload"]["source"] else True
	message = kwargs["message"]["content"] if "content" in kwargs["message"] else ""
	severity = kwargs["message"]["severity"] if "severity" in kwargs["message"] else 7
	self.AddToast(message,severity,isRemoteSource)

```

If you want a component to receive all messages sent through the system, you can add a method named ‘OnMessage\_ANY’. This method will catch any messages that do not have a message type specific receiver.

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/077a916def2003a0ab6d71ae8e7980c4b8aa753f.png)

[SimpleMessaging\_2017-10-04\_0732\_partial.proj](https://us1.discourse-cdn.com/inductiveautomation/original/2X/1/1b45e1133f2823d8916b7b02f76ffab37d6712d7.proj) (2.9 KB)
