# Calling the system.util.sendMessage function from a Module?

**URL:** <https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063>\
**Category:** 3rd Party Modules\
**Created:** [August 24, 2016, 8:22pm UTC](https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063 "2016-08-24T20:22:48Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![mgross](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mgross/32/3311_2.png) [@mgross](https://forum.inductiveautomation.com/u/mgross)\
**Post date:** [August 29, 2016, 2:35pm UTC](https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063/4 "2016-08-29T14:35:31Z")

</div>

What you will have to do is dispatch the message using MessageDispatchManager, and then you need to set up a message handler in a project that can call a script function in your module (example shown below).

Send code (Java):

```auto
MessageDispatchManager mdm = gatewayContext.getMessageDispatchManager();

PyDictionary payload = new PyDictionary(new PyObject[] {
        new PyString("Source"), new PyString("Gateway"),
        new PyString("Message"), new PyString("testMessage")
});

// Limit to Gateway scope
Properties filterParams = new Properties();
filterParams.setProperty(MessageDispatchManager.KEY_SCOPE, MessageDispatchManager.SCOPE_GATEWAY_ONLY);

// You must specify a project, as message handlers are configured in projects. 
mdm.dispatch("MyProject",
	"MyMessageHandler",
    payload,
    filterParams);
```

Jython Message handler in a project, which must be named “MyMessageHandler”:

```auto
def handleMessage(payload):
	mymodule.myFunction(payload)
```

---

_[View the full topic](https://forum.inductiveautomation.com/t/calling-the-system-util-sendmessage-function-from-a-module/12063)._
