Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XREAD not receiving messages via websocket #234

Open
gmussi opened this issue May 3, 2023 · 0 comments
Open

XREAD not receiving messages via websocket #234

gmussi opened this issue May 3, 2023 · 0 comments

Comments

@gmussi
Copy link

gmussi commented May 3, 2023

Hi there,

The following code DOES NOT receive messages when XADD is used:

const wsEndpoint = "ws://localhost:7379/.json";
const socket = new WebSocket(wsEndpoint);

socket.onopen = function(event) {
  console.log("WebSocket connection established");
  socket.send(JSON.stringify(["XREAD", "BLOCK", "0", "STREAMS", "test.mystream", "$"]));
  console.log("XREAD SENT");
};
socket.onmessage = function(event) {
  const message = JSON.parse(event.data);
  console.log("WebSocket message received:", message);
}

By comparison, the following code DOES WORK when XADD is used:

var previous_response_length = 0
xhr = new XMLHttpRequest()
xhr.open("GET", `http://localhost:7379/XREAD/BLOCK/0/STREAMS/test.mystream/$`, true);
xhr.onreadystatechange = checkData;
xhr.send(null);

function checkData() {
  if(xhr.readyState == 3)  {
    response = xhr.responseText;
    chunk = response.slice(previous_response_length);
    previous_response_length = response.length;
    console.log("chunk reading", chunk);
    }
  };

I am running the following on my docker-compose.yml:

webdis:
    image: nicolas/webdis:latest
    command: /usr/local/bin/webdis /config/webdis.json
    environment:
      REDIS_HOST: redis
      REDIS_PORT: 6379
    volumes:
      - ./docker/webdis/webdis.json:/config/webdis.json
    depends_on:
      - redis
    ports:  # allow connections from the Docker host on localhost, port 7379
      - "7379:7379"

Also, here is my webdis.config file:

{
	"redis_host":	"redis",

	"redis_port":	6379,
	"redis_auth":	null,

	"http_host":	"0.0.0.0",
	"http_port":	7379,

	"threads":	5,
	"pool_size": 20,

	"daemonize":	false,
	"websockets":	true,

	"database":	0,

	"acl": [
		{
			"disabled":	["DEBUG"]
		},

		{
			"http_basic_auth":	"user:password",
			"enabled":		["DEBUG"]
		}
	],

	"verbosity": 4,
	"logfile": "/dev/stderr"
}

The following line is printed on webdis when websocket is attempted:
[1] 03 May 08:19:42 D WS: /XREAD/BLOCK/0/STREAMS/test.mychannel/$

Additional information:

  • Using the same XREAD command using Rediscmd, redis-cli or regular nodejs code with redis adapter, works in all scenarios.

After a lot of trial-and-error, I did not manage to make websockets work for XREAD.
Any advice would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant