تهيئة وسيط STOMP المرحّل
استبدل الوسيط البسيط الموجود في الذاكرة بوسيط STOMP مرحّل، بحيث يمرر Spring الرسائل إلى وسيط فعلي مثل RabbitMQ لدعم التوسّع الأفقي.
تهيئة وسيط STOMP المرحّل درس مجاني في WebSockets & Real-Time Systems with Spring على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في WebSockets & Real-Time Systems with Spring، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة WebSockets & Real-Time Systems with Spring 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Limits of the Simple Broker
The default enableSimpleBroker keeps subscriptions and message routing in memory on one JVM. It is great for demos but cannot share state across instances, so it does not scale horizontally.
Enter the Broker Relay
A STOMP broker relay tells Spring to forward messages to a dedicated broker (RabbitMQ, ActiveMQ) that speaks STOMP. The broker, not the JVM, now handles routing and fan-out.
Why This Scales
With a central broker, every Spring instance connects to the same broker. A message published on node A reaches a subscriber on node B because both share the broker's topics and queues.
Enabling the Relay
Swap enableSimpleBroker for enableStompBrokerRelay in your config, pointing at the broker host and port.
registry.enableStompBrokerRelay("/topic", "/queue")
.setRelayHost("rabbitmq")
.setRelayPort(61613)
.setClientLogin("guest")
.setClientPasscode("guest");Enabling STOMP on RabbitMQ
RabbitMQ speaks STOMP through a plugin you must enable. Port 61613 is the STOMP default.
rabbitmq-plugins enable rabbitmq_stompApplication vs Broker Destinations
Keep the prefixes distinct:
/app→ routed to your@MessageMappingcontrollers/topic,/queue→ routed straight to the broker relay
registry.setApplicationDestinationPrefixes("/app");System Connection
Spring keeps a separate system connection to the broker for server-initiated messages (e.g. convertAndSend from a service). Configure its credentials too.
relay.setSystemLogin("guest")
.setSystemPasscode("guest")
.setSystemHeartbeatSendInterval(10000);Heartbeats with the Relay
The relay maintains heartbeats with the broker to detect a dead broker connection. If the broker goes down, Spring attempts to reconnect automatically.
What the Broker Brings
A real broker adds capabilities the simple broker lacks:
- Durable subscriptions that survive restarts
- Message persistence to disk
- Cross-node fan-out for clustering
- Monitoring and management UIs
Reactive/Virtual Thread Note
The relay uses a Reactor Netty TCP client under the hood. Ensure the reactor-netty dependency is present, or the relay fails to start with a missing-class error.
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
</dependency>Graceful Degradation
If the broker is unreachable at startup, the relay keeps retrying. Design clients to handle temporary delivery gaps and reconnect, rather than assuming the broker is always up.
Quick Check
Test your relay knowledge.
Recap
You moved routing to a real broker:
- The simple broker is in-memory and single-node only
enableStompBrokerRelayforwards to RabbitMQ/ActiveMQ over STOMP- Enable the broker's STOMP plugin (port 61613)
- Keep
/appfor controllers,/topicand/queuefor the broker - The relay gives clustering, persistence, and durable subscriptions
الأسئلة الشائعة
هل درس «تهيئة وسيط STOMP المرحّل» مجاني؟
نعم — نص درس «تهيئة وسيط STOMP المرحّل» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة WebSockets & Real-Time Systems with Spring، انتقل إلى CoddyKit PRO. تتضمن دورة WebSockets & Real-Time Systems with Spring 4 دروس في المجموع.
ماذا ستتعلم في «تهيئة وسيط STOMP المرحّل»؟
استبدل الوسيط البسيط الموجود في الذاكرة بوسيط STOMP مرحّل، بحيث يمرر Spring الرسائل إلى وسيط فعلي مثل RabbitMQ لدعم التوسّع الأفقي. تتمرن على WebSockets & Real-Time Systems with Spring مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ WebSockets & Real-Time Systems with Spring؟
لا تُشترط خبرة سابقة. WebSockets & Real-Time Systems with Spring على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «تهيئة وسيط STOMP المرحّل»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس WebSockets & Real-Time Systems with Spring هذا؟
نعم. كل درس في WebSockets & Real-Time Systems with Spring يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- الحاجة إلى وسطاء رسائل خارجيين
- الدمج مع RabbitMQ وKafka
- بنيات WebSocket الموزعة
- تهيئة وسيط STOMP المرحّل