0
プッシュ通知機能を持つシステムを構築しています.Jerseyを使用してAPIを作成しています。
私は彗星のアプローチについてarticleを読み、次のコードで終わる:私のデバッグから
Index.js
コール再帰的なAjaxの場合のカントのアクセス成功関数
function checkExamNotification() {
$.ajax({
url: contextPath + '/api/notification/checkExamNotification',
type: 'get',
data: {
accountId: accountId,
sessionId: sessionId
},
success: function (res) {
console.log("success");
displayNumberOfNotification();
checkExamNotification();
},
error: function (jqXHR, textStatus, errorThrown) {
if (textStatus === "timeout") {
checkExamNotification();
}
}
});
}
$(document).ready(function() {
$.ajaxSetup({
timeout: 1000*60*3
});
checkExamNotification();
});
確認試験の通知API
@GET
@Path("/checkExamNotification")
public Response checkExamNotification(@QueryParam("accountId") int accountId, @QueryParam("sessionId") String sessionId) throws InterruptedException {
if (memCachedClient.checkSession(sessionId, accountId)) {
while (!examNotificationQueue.hasItems()) {
Thread.sleep(5000);
}
ExamNotificationQueueItemModel examNotificationQueueItemModel = examNotificationQueue.dequeue();
if (examNotificationQueueItemModel.getAccountId() == accountId) {
LOGGER.info("[START] Check exam notification API");
LOGGER.info("Account ID: " + accountId);
LOGGER.info("Get notification with exam ID: " + examNotificationQueueItemModel.getExamId());
ExamEntity exam = examDAO.findById(examNotificationQueueItemModel.getExamId());
NotificationEntity notification = notificationDAO.findByExamId(exam.getExamid());
notification.setSend(1);
notificationDAO.getEntityManager().getTransaction().begin();
notificationDAO.update(notification);
notificationDAO.getEntityManager().getTransaction().commit();
LOGGER.info("[END]");
String result = gson.toJson(examNotificationQueueItemModel);
return Response.status(200).entity(result).build();
} else {
examNotificationQueue.enqueue(examNotificationQueueItemModel);
Thread.sleep(5000);
checkExamNotification(accountId, sessionId);
}
}
return Response.status(200).entity(gson.toJson("timeout")).build();
}
、 APIはリターンを終了しましたが、成功イベントSOMETIMESは発生しませんでした。
はい、時にはコンソールログが成功することもありますが、時にはコンソールログが成功しないことがあります。
誰にでもこのケースを説明できますか?
ありがとうございます。どんな助けもありがとう。
私はこれを推進しているか表示されません。いくつかの送られたイベント(SSE)のジャージのサポートを見てみるべきです。これは実際のプッシュを使用します。 –
遅く返事を申し訳ありません。私はあなたの道を試みます。しかし、なぜそれが適切に応答を返さなかったのか説明できますか? –