function StartSSE(id) {
var source = new EventSource('/api/sse/message/' + id);
var ul = document.getElementById('sse');
source.onmessage = function (e) {
var li = document.createElement('li');
if (!!e.data) {
var retrievedData = JSON.parse(e.data)
li.textContent = retrievedData.Message;
ul.appendChild(li);
console.log(retrievedData.Message);
}
}
}
SSE Client
전송서버
FrontSample
ActorModel
public class UserActor : ReceiveActor
{
private Queue<Notification> notifications = new Queue<Notification>();
public UserActor()
{
ReceiveAsync<Notification>(async msg =>
{
if (msg.IsProcessed == false)
{
notifications.Enqueue(msg);
}
});
ReceiveAsync<CheckNotification>(async msg =>
{
if (notifications.Count > 0)
{
Sender.Tell(notifications.Dequeue());
}
else
{
Sender.Tell(new EmptyNotification());
}
});
}
}
Document