-
1. Re: Question on broadcasting messages
csa Oct 13, 2011 3:05 PM (in response to stab)Yes, injecting the bus is fine. The problem is your subject. You are sending a message to "HelloWorldService" from within the HelloWorldService callback. You need to use a separate subject for the broadcast messages.
-
2. Re: Question on broadcasting messages
stab Oct 13, 2011 4:41 PM (in response to csa)Thanks, I see now that I've misunderstood how to subscribe to a service(read the manual would a colleague had said to me).
I modified the client code and added a subscription to "HelloWorldClient":
@EntryPoint
public class HelloWorldClient extends VerticalPanel {
private int n = 0;
@Inject
private MessageBus bus;
@PostConstruct
public void init() {
Button button = new Button("hello!");
bus.subscribe("HelloWorldClient", new MessageCallback() {
@Override
public void callback(Message message) {
n++;
Window.alert("From Server(messagenr:" + n + ") - " + message.get(String.class, MessageParts.Value));
}
});
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
MessageBuilder.createMessage()
.toSubject("HelloWorldService")
.withValue("Hello, There!")
.done()
.sendNowWith(bus);
}
});
add(button);
RootPanel.get().add(this);
}
}
and the server code to:
@Service
public class HelloWorldService implements MessageCallback {
@Inject
private MessageBus bus;
@Override
public void callback(Message message) {
// Send a message to the 'HelloWorldClient'.
MessageBuilder.createMessage()
.toSubject("HelloWorldClient")
.signalling()
.with("text", "Hi There")
.noErrorHandling()
.sendNowWith(bus);
}
}
Now I get a response in the client but no messsage, how come?
-
3. Re: Question on broadcasting messages
csa Oct 13, 2011 5:17 PM (in response to stab)That's because you set the message part "text" but ask for the value. In your client callback use message.get(String.class, "text").
-
4. Re: Question on broadcasting messages
stab Oct 13, 2011 5:23 PM (in response to csa)Thanks a lot, working very nice!!!!