skip to Main Content

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.

2

Answers


  1. I have tried with your docker compose file. I see the config file is updated

    root@5aabba6324bc:/pulsar# more conf/standalone.conf | grep webSocketSessionIdleTimeoutMillis
    webSocketSessionIdleTimeoutMillis=36000000
    

    And it also can be found in the log

    Attaching to downloads_pulsar_1
    pulsar_1  | [conf/standalone.conf] Applying config webSocketSessionIdleTimeoutMillis = 36000000
    pulsar_1  | [conf/standalone.conf] Updating config webSocketSessionIdleTimeoutMillis = 36000000
    pulsar_1  | [AppClassLoader@18b4aac2] info AspectJ Weaver Version 1.9.2 built on Wednesday Oct 24, 2018 at 15:43:33 GMT
    pulsar_1  | [AppClassLoader@18b4aac2] info register classloader sun.misc.Launcher$AppClassLoader@18b4aac2
    pulsar_1  | [AppClassLoader@18b4aac2] info using configuration file:/pulsar/lib/org.apache.pulsar-pulsar-zookeeper-utils-2.6.0.jar!/META-INF/aop.xml
    pulsar_1  | [AppClassLoader@18b4aac2] info using configuration file:/pulsar/lib/org.apache.pulsar-pulsar-zookeeper-2.6.0.jar!/META-INF/aop.xml
    pulsar_1  | [AppClassLoader@18b4aac2] info register aspect org.apache.pulsar.broker.zookeeper.aspectj.ClientCnxnAspect
    pulsar_1  | [AppClassLoader@18b4aac2] info register aspect org.apache.pulsar.zookeeper.FinalRequestProcessorAspect
    

    Looks like it’s not the issue of the update config file script.
    But maybe an issue with the WebSocket implementation.

    Have you tried a new version such as 2.9.3 or 2.10.1? I’m not sure
    if the issue has been fixed or not. If you can also see the issue
    on a new version. It’s better to raise up a Github issue here.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search