0Pricing
Redis Caching & Messaging (Pub/Sub, Streams) · Ders

Tüketici Gruplarına Giriş

Tüketici Gruplarının birden çok tüketicinin akışı iş birliği içinde ve güvenilir biçimde işlemesini nasıl sağladığını anlayın.

Tüketici Gruplarına Giriş, CoddyKit'te ücretsiz bir Redis Caching & Messaging (Pub/Sub, Streams) dersidir. Bu, 4 dersinin 1. 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, Redis Caching & Messaging (Pub/Sub, Streams) öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Redis Caching & Messaging (Pub/Sub, Streams) kursu toplamda 4 dersten oluşur.

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

What are Consumer Groups?

Redis Streams are powerful for logging and event sourcing. But what if multiple applications or instances need to process the same stream data, without duplicating work?

This is where Consumer Groups come in. They are a core feature of Redis Streams designed for reliable, shared message processing.

The Challenge: Multiple Readers

Imagine two services, Service A and Service B, both needing to process every new order from an orders_stream.

If both services simply use XREAD, they would both receive and process all messages, leading to duplicated effort or inconsistent states.

  • How do they know which messages are already processed?
  • How do they share the workload?

Solving Shared Stream Processing

Consumer Groups provide a way for multiple clients (consumers) to jointly read from the same Redis Stream.

They ensure that:

  • Each message is delivered to only one consumer within the group.
  • The state (which messages are pending, which are acknowledged) is managed by Redis.
  • Consumers can recover and resume processing from where they left off.

Key Concepts: Group, Consumer, PEL

Let's define the core parts of a Consumer Group:

  • Stream: The Redis Stream holding the messages.
  • Consumer Group: A logical group of consumers processing a stream.
  • Consumer: An individual client instance within a group.
  • Pending Entry List (PEL): A list maintained by Redis for each consumer, tracking messages that have been delivered but not yet acknowledged.

Setting Up Your First Group

Before consumers can join, a Consumer Group must be created on a specific stream. We use the XGROUP CREATE command.

The MKSTREAM option automatically creates the stream if it doesn't exist.

XGROUP CREATE my_stream my_group 0 MKSTREAM

Populating the Stream

Let's add a few messages to our my_stream so we have something to read. Remember, XADD is how you add entries to a stream.

XADD my_stream * sensor_id 1 temp 25.5
XADD my_stream * sensor_id 2 temp 24.9
XADD my_stream * sensor_id 1 temp 26.1

Consumers Joining the Group

Consumers read from a group using the XREADGROUP command. You specify the group name, the consumer name, and the stream ID to start reading from.

The special ID > means "read only new, unread messages that have not been delivered to any other consumer in this group yet."

XREADGROUP GROUP my_group consumer1 COUNT 1 STREAMS my_stream >

Confirming Message Processing (XACK)

After a consumer processes a message, it must acknowledge it using XACK. This tells Redis the message is handled and can be removed from the consumer's Pending Entry List (PEL).

This is crucial for reliability and prevents messages from being re-delivered if a consumer crashes.

XACK my_stream my_group 1678881234567-0

Why XACK Matters

Acknowledging messages is vital for two main reasons:

  • Reliability: If a consumer fails before acknowledging, the message remains in its PEL and can be claimed by another consumer later.
  • Resource Management: Unacknowledged messages stay in the PEL, consuming memory. Acknowledging keeps the PEL clean and efficient.

Consumer Group Basics

Which Redis command is used to create a new Consumer Group for a stream?

Recap: Consumer Groups

In this lesson, you learned about Redis Consumer Groups and how they enable multiple consumers to reliably process messages from a single stream, ensuring each message is handled only once.

You now understand the roles of groups, consumers, and the Pending Entry List (PEL), and how to use XGROUP CREATE, XREADGROUP, and XACK.

Next, we'll dive deeper into implementing consumer group logic and handling pending messages!

Sıkça Sorulan Sorular

“Tüketici Gruplarına Giriş” dersi ücretsiz mi?

Evet — “Tüketici Gruplarına Giriş” 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 Redis Caching & Messaging (Pub/Sub, Streams) kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Redis Caching & Messaging (Pub/Sub, Streams) kursu toplamda 4 dersten oluşur.

“Tüketici Gruplarına Giriş” dersinde ne öğreneceğim?

Tüketici Gruplarının birden çok tüketicinin akışı iş birliği içinde ve güvenilir biçimde işlemesini nasıl sağladığını anlayın. Redis Caching & Messaging (Pub/Sub, Streams) 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.

Redis Caching & Messaging (Pub/Sub, Streams) öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Redis Caching & Messaging (Pub/Sub, Streams), 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 1. dersidir.

“Tüketici Gruplarına Giriş” 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 Redis Caching & Messaging (Pub/Sub, Streams) dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Redis Caching & Messaging (Pub/Sub, Streams) 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. Tüketici Gruplarına Giriş
  2. Tüketici Grubu Mantığını Uygulama
  3. Bekleyen Mesajları ve Hataları Ele Alma
  4. Tüketici Grubu Gecikmesini İzleme
← Redis Caching & Messaging (Pub/Sub, Streams) Sayfasına Dön