Unable to get sendMessage to work

Not sure what I’m missing here, but my script does not work. This is my test script.

project = "myProject"
messageHandler = "upsStatus"
message = "test message!"
payload = {"message":message}
hostName = "devPi-ip-100"
	print "send message failed"

client message handler

def handleMessage(payload):
	message = payload["message"]

All I can say is make sure the project, messagehandler, and host names are all correct.

If you do a try: except: and print the error, or just get rid of the try/except so the error bubbles up. Does any error the say?

Also make sure the message Handler on the client is named exactly the same as what you are passing.
It is case sensitive.

The sendMessage script does not error out, it completes successfully. The message just never makes it to the client. I tried using the diagnostics window and putting the client message handler in debug mode. when I send the message nothing shows up there. I’ve checked all the names a hundred times, and tried it without the hostname. no matter what it doesn’t work.

I just checked one of ours and I notice we are explicitly setting the parameters in the sendMessage call.

app = "myProject"
msgHandler = "upsStatus"
msg = "test message!"
content = {"message":message}
host = "devPi-ip-100"
	print "send message failed"

That did the trick, I didn’t notice the explicit definition in the call. Much appreciated!

This has to do with how python (and jython) are interpreting the arguments you are sending. Since you weren’t sending the arguments as kwargs originally, they were essentially being interpreted based on their position, so scope happened to fall into the correct position because it is the first “optional” argument, but hostname would have been interpreted as clientSessionId, as that is the next optional argument.

As you’ve already found, supplying the arguments with their associated keyword clears everything up as the arguments are now explicitly defined for the function.

1 Like

@cmallonee Can you use wildcards in the hostName arg?

hostName = 'cush-ip*'

Doesn’t seem so, looks like a for loop and a list is the way to handle this

You could always pull the node list and then filter and send.

nodes = system.util.getSessionInfo()
listnumber = len(nodes)
for x in range(listnumber):
	if 'cush-ip' in nodes[x][2]: