因此,這是幾個月前在這個項目上的工作。我正在使用Google App Engine的Channel API將消息推送到我的GWT應用程序。我正在使用http://code.google.com/p/gwt-gae-channel/通過GWT進行交互。GAE頻道重複發送第一條消息
可以說,我發送1個消息給客戶端:「第一條消息」
客戶端將收到消息,「第一條消息」就好了。
然後我們假設我向客戶端發送另一條消息「Second Message」。
客戶端將再次收到消息「First Message」。
這將繼續發生。有些情況下,我會收到第二條消息,並且會被重複卡住的消息。
當我最後關閉頁面並關閉頻道時,我再次收到重複的消息,而無需從服務器發送任何內容。
有沒有人有任何想法是怎麼回事?我不認爲這是在幾個月前正在處理這個問題時發生的,我沒有看到GAE Channel API的更改。
下面是一些代碼:
String json = AutoBeanHelper.toJson(proxy);
log.fine("Item's JSON Received: " + json);
List<ChannelEntity> channels = channelDAO.getByUserId();
if (channels.size() > 1) {
log.warning("Multiple channels for single user detected.");
}
ChannelService channelService = ChannelServiceFactory.getChannelService();
for (ChannelEntity channel : channels) {
channelService.sendMessage(new ChannelMessage(channel.getClientId(), json));
}
所以每當我存儲特定類型的新項目(這是在實體更新功能): 1.我把它變成JSON。 2.然後我記錄該JSON。 3.我得到那個用戶頻道。 4.我將它發送到該用戶頻道。
當我查看我的日誌時,發現上面顯示的變量正確顯示,意思是我正在記錄正確的JSON消息,但是當我在客戶端上的警報中顯示JSON時,只要它到達客戶端,它就是以前的消息,似乎被阻止重複。我真的不明白我在這裏可能會做錯什麼。
讓我知道你是否想看到代碼的另一部分。良好的措施,這裏是客戶端的代碼:我看到那麼,有人在他們的代碼中的錯誤很多的問題,但認爲這是框架的一部分
eventBus.addHandler(ReceivedChannelTokenEvent.TYPE, new ReceivedChannelTokenEventHandler() {
@Override
public void onEvent(ReceivedChannelTokenEvent event) {
ChannelFactory.createChannel(event.getChannelToken(), new ChannelCreatedCallback() {
@Override
public void onChannelCreated(Channel channel) {
final Socket channelSocket = channel.open(new SocketListener() {
@Override
public void onOpen() {
Window.alert("Channel Opened");
}
@Override
public void onMessage(String json) {
Window.alert(json);
eventBus.fireEvent(new MessageReceivedEvent(json));
}
@Override
public void onError(SocketError error) {
Window.alert("Channel Error: " + error.getDescription());
if (error.getDescription().equals(CHANNEL_ERROR_TOKEN_TIME_OUT)) {
eventBus.fireEvent(new ChannelTimeOutEvent());
}
}
@Override
public void onClose() {
Window.alert("Channel Closed.");
}
});
Window.addWindowClosingHandler(new Window.ClosingHandler() {
@Override
public void onWindowClosing(ClosingEvent event) {
channelSocket.close();
}
});
}
});
}
});
這是發生在開發應用程序服務器還是生產? –
好問題。這發生在生產應用程序上。 – spierce7