0Pricing
WebSockets & Real-Time Systems with Spring · Ders

Çevrimiçi Durumu ve Kullanıcı Varlığını İzleme

Kimlerin çevrimiçi olduğunu gösteren gerçek zamanlı bir varlık sistemi oluşturun; bağlanma ve bağlantı kesilmesi olaylarını yayınlayıp canlı kullanıcı durumunu gösterin.

Çevrimiçi Durumu ve Kullanıcı Varlığını İzleme, CoddyKit'te ücretsiz bir WebSockets & Real-Time Systems with Spring dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, WebSockets & Real-Time Systems with Spring öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. WebSockets & Real-Time Systems with Spring kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

What Is Presence?

Presence is knowing who is currently online: the green dots in chat apps, the live cursors in collaborative editors, the active-now lists. It is one of the most requested real-time features.

Presence Is About Lifecycle Events

The core insight: presence is derived from connection lifecycle. When a session opens, mark the user online; when it closes, mark them offline, then broadcast the change.

Listening to Connect Events

Spring publishes a SessionConnectedEvent when a STOMP session is established. Use it to record the user as online.

@EventListener
public void onConnect(SessionConnectedEvent e) {
  String user = e.getUser().getName();
  presence.markOnline(user);
  broadcast(user, "ONLINE");
}

Listening to Disconnect Events

A matching SessionDisconnectEvent fires on close. Mark the user offline and broadcast it.

@EventListener
public void onDisconnect(SessionDisconnectEvent e) {
  String user = userFor(e.getSessionId());
  presence.markOffline(user);
  broadcast(user, "OFFLINE");
}

Storing Presence State

For a single server a concurrent map works. For a cluster, store presence in Redis so every node sees the same online set.

redis.opsForSet().add("online:users", username);
redis.opsForValue().set("presence:" + username, "ONLINE", Duration.ofMinutes(2));

Broadcasting Status Changes

Push each change to a presence topic so every interested client updates its UI live.

messagingTemplate.convertAndSend("/topic/presence",
  new PresenceEvent(username, status));

Multiple Tabs and Devices

A user with two tabs has two sessions. Reference-count them: only mark offline when the last session closes, or you will flicker the status.

Handling Ungraceful Disconnects

A crash may not send a clean close. Pair presence with heartbeats and a TTL: if no heartbeat arrives before the key expires, treat the user as offline.

Last-Seen Timestamps

Beyond online/offline, record a last-seen time on disconnect. The UI can then show "active 5 minutes ago" for offline users.

redis.opsForValue().set("lastseen:" + username, Instant.now().toString());

Sending the Initial Snapshot

When a client first connects it needs the current online list, not just future changes. Send a snapshot on subscription, then stream deltas.

@SubscribeMapping("/presence.init")
public Set<String> initial() {
  return presence.onlineUsers();
}

Privacy Considerations

Presence can leak behavior patterns. Offer an invisible mode and respect it server-side, so a user who opts out is never broadcast as online.

Quick Check

Test your presence knowledge.

Recap

You built presence:

  • Presence derives from connect/disconnect lifecycle events
  • Use SessionConnectedEvent / SessionDisconnectEvent and broadcast changes
  • Store shared state in Redis for clustering; reference-count multiple sessions
  • Pair with heartbeats and TTLs to catch ungraceful disconnects
  • Send an initial snapshot, track last-seen, and honor invisible mode

Sıkça Sorulan Sorular

“Çevrimiçi Durumu ve Kullanıcı Varlığını İzleme” dersi ücretsiz mi?

Evet — “Çevrimiçi Durumu ve Kullanıcı Varlığını İzleme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve WebSockets & Real-Time Systems with Spring kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. WebSockets & Real-Time Systems with Spring kursu toplamda 4 dersten oluşur.

“Çevrimiçi Durumu ve Kullanıcı Varlığını İzleme” dersinde ne öğreneceğim?

Kimlerin çevrimiçi olduğunu gösteren gerçek zamanlı bir varlık sistemi oluşturun; bağlanma ve bağlantı kesilmesi olaylarını yayınlayıp canlı kullanıcı durumunu gösterin. WebSockets & Real-Time Systems with Spring ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

WebSockets & Real-Time Systems with Spring öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te WebSockets & Real-Time Systems with Spring, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“Çevrimiçi Durumu ve Kullanıcı Varlığını İzleme” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu WebSockets & Real-Time Systems with Spring dersinde kod yazıp çalıştırabilir miyim?

Evet. Her WebSockets & Real-Time Systems with Spring dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Sunucu Tarafından Gönderilen Olaylar (SSE) ve WebSockets
  2. Gerçek Zamanlı Veri İtme Mimarileri
  3. Kullanıcı Bildirimlerini Hayata Geçirme
  4. Çevrimiçi Durumu ve Kullanıcı Varlığını İzleme
← WebSockets & Real-Time Systems with Spring Sayfasına Dön