Kubernetes集群中django-eventstream与Pushpin无消息接收问题求助
Django-Eventstream + Pushpin 在Kubernetes中无法接收send_event消息的问题
我正在Kubernetes集群中部署django-eventstream和Pushpin,目前能成功订阅SSE流,但调用send_event发送的数据始终无法传递到客户端,且无任何错误提示。目标是实现应用日志的实时流更新功能。
Django 配置
settings.py
MIDDLEWARE = [ ... 'django_grip.GripMiddleware' ] INSTALLED_APPS = [ 'django_eventstream', ... ] GRIP_URL = 'http://pushpin:5561'
urls.py
path('event/logmessage/', include(django_eventstream.urls), {'channels': ['logmessage']}),
logutility.py(日志发送逻辑)
import logging from datetime import datetime from django_eventstream import send_event from django.core.serializers import serialize def logMessage(level, source, message): from .models import LogMessage logger = logging.getLogger(__name__) if level in ['DEBUG', 'INFO', 'WARNING', 'ERROR']: level = logging.getLevelName(level) logger.debug('Log message received: {0} {1} {2}'.format(logging.getLevelName(level), source, message)) logger.log(level, (source + ' - ' + message)) lm = LogMessage.objects.create(msg_time=datetime.now(), level=logging.getLevelName(level), source=source, msg_text=message) lmjson = serialize('json', [lm]) send_event('logmessage', 'message', lmjson)
前端代理配置(httpd)
ProxyPass /event/ http://pushpin:7999/event/ ProxyPassReverse /event/ http://pushpin:7999/event/
React客户端代码
componentDidMount() { this.getData(this.state.toggleDebug) if ('EventSource' in window) { let source = new EventSource("/event/logmessage"); source.onopen = (e) => console.log("SSE connection made", e); source.onmessage = (e) => console.log("SSE data received", e.data); } }
Pushpin Kubernetes部署清单
apiVersion: v1 kind: ConfigMap metadata: name: pushpin namespace: {{ .Values.namespace }} data: routes: | *,debug nrs:8800 //our app --- apiVersion: v1 kind: Service metadata: labels: mm.service: pushpin name: pushpin namespace: {{ .Values.namespace }} spec: ports: - name: pushpin port: 7999 targetPort: 7999 selector: mm.service: pushpin --- apiVersion: apps/v1 kind: ReplicaSet metadata: creationTimestamp: null labels: mm.service: pushpin name: pushpin namespace: {{ .Values.namespace }} spec: replicas: 1 selector: matchLabels: mm.service: pushpin template: metadata: creationTimestamp: null labels: mm.service: pushpin spec: containers: - image: fanout/pushpin name: pushpin ports: - containerPort: 7999 volumeMounts: - mountPath: /etc/pushpin/routes name: nrs-pushpin subPath: routes hostname: pushpin restartPolicy: Always volumes: - name: nrs-pushpin configMap: name: pushpin items: - key: routes path: routes ---
现象与日志
访问页面时,客户端能触发SSE connection made事件,但从未收到SSE data received,尽管logutility.py持续接收消息并调用send_event。集群入口流量经Keycloak验证后路由到前端服务,这部分正常,问题仅出在消息传递环节。
Pushpin初始连接日志:
[INFO] 2023-04-10 23:11:02.796 [zurl] IN id=f5c16c86-35e0-43ce-a717-08dc2c3a9ef7, GET http://pushpin:7999/event/logmessage [INFO] 2023-04-10 23:11:02.806 [zurl] OUT id=f5c16c86-35e0-43ce-a717-08dc2c3a9ef7 code=301 0 [INFO] 2023-04-10 23:11:02.810 [proxy] GET http://pushpin:7999/event/logmessage -> nrs:8800 ref=https://nrs.<our domain>/ code=301 0 [INFO] 2023-04-10 23:11:02.885 [zurl] IN id=fbb1f830-41c7-49cd-a7ab-59969d0c95f9, GET http://pushpin:7999/event/logmessage/ [INFO] 2023-04-10 23:11:02.891 [zurl] OUT id=fbb1f830-41c7-49cd-a7ab-59969d0c95f9 code=200 2077 [INFO] 2023-04-10 23:11:02.910 [handler] subscribe http://pushpin:7999/event/logmessage/ channel=events-logmessage [INFO] 2023-04-10 23:11:02.910 [handler] subscribe http://pushpin:7999/event/logmessage/ channel=user-anonymous [INFO] 2023-04-10 23:11:02.914 [proxy] GET http://pushpin:7999/event/logmessage/ -> nrs:8800 ref=https://nrs.<our domain>/ accept [INFO] 2023-04-10 23:11:03.993 [zurl] IN id=49c61ed3-2bfd-4400-a6f4-e63a3e29f652, GET http://pushpin:7999/event/logmessage/?link=next&recover=true&es-meta=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJlcyIsImV4cCI6MTY4MTE3MTg2MiwiY2hhbm5lbHMiOlsibG9nbWVzc2FnZSJdLCJ1c2VyIjoiYW5vbnltb3VzIn0.gfBVwH7APFGfxJqOHERTwlHdWo-5vrxwrWet1R2iFHk [INFO] 2023-04-10 23:11:04.005 [zurl] OUT id=49c61ed3-2bfd-4400-a6f4-e63a3e29f652 code=200 0 [INFO] 2023-04-10 23:11:04.007 [handler] GET http://pushpin:7999/event/logmessage/?link=next&recover=true&es-meta=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJlcyIsImV4cCI6MTY4MTE3MTg2MiwiY2hhbm5lbHMiOlsibG9nbWVzc2FnZSJdLCJ1c2VyIjoiYW5vbnltb3VzIn0.gfBVwH7APFGfxJqOHERTwlHdWo-5vrxwrWet1R2iFHk route=*,*,*,* code=200 0
疑问
不确定从何处调试连接,也不知道如何测试Pushpin/django-eventstream是否实际尝试发送消息。后续计划用通道选择器简化URL,但当前简单场景已遇阻。
内容的提问来源于stack exchange,提问作者Cthulhujr
相关产品推荐
相关产品推荐

