Below is my configuration for running pulsar as a standalone version in docker-compose:
pulsar:
image: apachepulsar/pulsar:2.6.0
ports:
- 8080:8080
- 6650:6650
environment:
PULSAR_MEM: " -Xms512m -Xmx512m -XX:MaxDirectMemorySize=1g"
PULSAR_PREFIX_webSocketSessionIdleTimeoutMillis: 36000000
command: bash -c "bin/apply-config-from-env.py conf/standalone.conf && bin/pulsar standalone"
I am connecting pulsar from browser-client side as consumer. I am using JS websocket for connection.
Code for Client side :
new WebSocket(`ws://broker-service-url:8080/ws/v2/consumer/persistent/public/default/my-topic`)
And socket connection is successful.
Docker container is being created and after inspecting
/pulsar/conf/standalone.conf
in docker container, i can see updated value in standalone.conf file also.
As per findings on internet, I found that we can override configuration by adding prefix PULSAR_PREFIX_ and running command bash -c "bin/apply-config-from-env.py conf/standalone.conf && bin/pulsar standalone".I want to increase timeout for websocket idle connection.By default it is 30 seconds and I want to increase it.
Still websocket connection is disconnected from client side after 30 seconds which is default.
It looks not a problem with the server side. I try to test if on my laptop, here is the log from the standalone
2022-08-23T12:05:45,037+0800 [pulsar-web-57-12] INFO org.eclipse.jetty.server.RequestLog - 127.0.0.1 - - [23/Aug/2022:12:05:44 +0800] "GET /ws/v2/consumer/persistent/public/default/my-topic/my-sub HTTP/1.1" 101 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" 538
2022-08-23T12:05:45,041+0800 [pulsar-web-57-12] INFO org.apache.pulsar.websocket.AbstractWebSocketHandler - [/127.0.0.1:62398] New WebSocket session on topic persistent://public/default/my-topic
2022-08-23T12:10:45,052+0800 [Connector-Scheduler-76fa3dd8-1] INFO org.apache.pulsar.websocket.AbstractWebSocketHandler - [/127.0.0.1:62398] WebSocket error on topic persistent://public/default/my-topic : java.util.concurrent.TimeoutException: Idle timeout expired: 300002/300000 ms
2022-08-23T12:10:45,054+0800 [pulsar-io-29-1] INFO org.apache.pulsar.broker.service.ServerCnx - [/127.0.0.1:62399] Closing consumer: consumerId=0
2022-08-23T12:10:45,055+0800 [pulsar-io-29-1] INFO org.apache.pulsar.broker.service.AbstractDispatcherSingleActiveConsumer - Removing consumer Consumer{subscription=PersistentSubscription{topic=persistent://public/default/my-topic, name=my-sub}, consumerId=0, consumerName=8092a, address=/127.0.0.1:62399}
2022-08-23T12:10:45,055+0800 [pulsar-io-29-1] INFO org.apache.pulsar.broker.service.ServerCnx - [/127.0.0.1:62399] Closed consumer, consumerId=0
2022-08-23T12:10:45,055+0800 [pulsar-client-io-87-2] INFO org.apache.pulsar.client.impl.ConsumerImpl - [persistent://public/default/my-topic] [my-sub] Closed consumer
2022-08-23T12:10:45,057+0800 [Connector-Scheduler-76fa3dd8-1] INFO org.apache.pulsar.websocket.AbstractWebSocketHandler - [/127.0.0.1:62398] Closed WebSocket session on topic persistent://public/default/my-topic. status: 1001 - reason: java.util.concurrent.TimeoutException: Idle timeout expired: 300002/300000 ms
The session closed as expected (5min by default) not 30s But I'm not using the JS WebSocket Client.
It looks like should be an issue with the JS WebSocket Client.
BTW, the URL you provided ws://broker-service-url:8080/ws/v2/consumer/persistent/public/default/my-topic
is not correct which missed the subscription name.
After change to ws://url:8080/ws/v2/consumer/persistent/public/default/my-topic/my-sub
, I'm able to connect to the standalone.