fanout / django-eventstream

Server-Sent Events for Django
MIT License
664 stars 88 forks source link

Can't connect to dynamic channels #101

Open owenljn opened 1 year ago

owenljn commented 1 year ago

Hi,

I tried to specify a list of dynamic channels using formatting based on view keywords, the configuration looks like below:

application = ProtocolTypeRouter({
    'http': URLRouter([
        path('events/<obj_id>', AuthMiddlewareStack(URLRouter(
            django_eventstream.routing.urlpatterns
        )), { 'format-channels': [object-{obj_id}] }),
        re_path(r'', get_asgi_application()),
    ]),
})

in my views.py, I have this:

def home(request):
    context = {}
    context['url'] = '/events/{obj_id}'
    context['last_id'] = get_current_event_id(['time', 'time2'])
    return render(request, 'timeapp/home.html', context)

However, it's not able to connect to any channel, can you help take a look see what was wrong with my configuration? Thanks.

Edit: If I want to specify a fixed list of channels, then I got this error: stream error: bad-request: Invalid request: Channel limit exceeded. it seems the maximum number of channels I can specify is 10, how do I specify more than 10 channels?

jkarneges commented 1 year ago

The above code has some typos?

For the format-channels value, I think you meant:

['object-{obj_id}']

And I'm not sure {obj_id} gets substituted for anything here:

context['url'] = '/events/{obj_id}'

Regarding the channel limit, indeed it is limited to 10 per connection. It would probably not be hard to make this configurable, but a large number could impact scalability. How many channels are you needing?