我正在尝试让django-eventstream和Pushpin在kubernetes集群中工作。我可以成功订阅流,但我从未接收到通过send_event发送的数据。我没有收到任何错误信息来告诉我哪里出了问题。
我正在尝试工作的流是一个日志流到我的应用程序,所以它经常得到更新。
我的设置:使用Django -eventstream,在我的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)
我的web应用程序与运行httpd的前端容器对话(我知道,我们即将切换到nginx)httpd . conf -
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);
}
}
我拉入图钉图像,并将其设置为以下清单:
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连接',但是我从来没有看到'SSE data received',即使逻辑程序是常规地接收消息并调用send_event。
在集群中设置的方式是,我有一个入口点,将流量路由到我的前端服务(通过keycloak验证后),并且初始的东西似乎都很好。它只是Django中的send_event没有返回到我的客户端的某个地方。
当我最初连接时,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-eventstreams试图发送消息。我知道有通道选择器,我将最终简化我的url路径(因为我有几个通道,我将最终发送),但想要直接开始与所有这些,但不幸的是,这并不像我希望的那样容易。
谢谢!
这样做了,当我分别在复制集和服务中为5561添加了额外的containerPort和第二个端口声明后,工作顺利。