jxcore / jxm

Incredibly fast messaging backend for Node.JS / JXcore
http://jxm.io
Other
226 stars 30 forks source link

How to define customMethod for sentToGroup call? #30

Closed BennieBe closed 9 years ago

BennieBe commented 9 years ago

Hi,

I am wondering a bit about where I have to define the customMethod for the sendToGroup function? Specifically, I am referring to this part of the documentation in Java API Client: SendToGroup(String groupName, String methodName, Object params) Sends message to all clients, that have already subscribed to the specific groupName. The message is passed as params argument to the target's method named methodName. The "addText" method should be available on every client, which is subscribed to programmers group. While invoking the addText method at each client, the server will pass "Hello from client!" as an argument: client.SendToGroup("programmers", "addText", "Hello from client!");

However, if I define a public void customMethod() inside of my java file, I always receive that the method could not be found: xm.Client@fd2c076: Method customMethod wasn't exist on target object.: Critical

Where and how do I need to define this customMethod that is invoked by each client?

Thanks for your help!

ktrzeciaknubisa commented 9 years ago

Hi. Take a look at the Client-side-subscription sample's code in ClientMethods.java. Inside the CustomMethods class there is defined a method (receiver of message which is sent to group):

public void clientsMethod(Object response) {
    System.out.println("Received from the server: " + response.toString());
    super.client.Close();
}

Then in Main.java you have a call, which sends inside a group to the method named clientsMethod:

cli.SendToGroup("programmers", "clientsMethod", "Hello from Java client!", null);

Also don't forget to pass CustomMethods class to the constructor when creating a client:

Client client = new Client(new CustomMethods(), "channels",
    "NUBISA-STANDARD-KEY-CHANGE-THIS", "localhost", 8000, false, true);

It's all in the samples. Let me know if that helps you.

ktrzeciaknubisa commented 9 years ago

See also the docs for new Client(localTarget, appName, appKey, url, port, secure).

BennieBe commented 9 years ago

Hey ktrzeciaknubisa,

It works well :+1: thanks again for your help, very much appreciated!