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

Cant make it work with wss #1

Closed
eduardo-g-silva opened this issue Jan 17, 2023 · 3 comments
Closed

Cant make it work with wss #1

eduardo-g-silva opened this issue Jan 17, 2023 · 3 comments
Labels
good first issue Good for newcomers

Comments

@eduardo-g-silva
Copy link

eduardo-g-silva commented Jan 17, 2023

Hi, I am following the sample to read messages from stomp using wss because the server I need to get the messages dosn't support tcp.

I manage to connect but I always get null in the body.
Looks like the subscription of the queue is not working or something else that i can't figure out.

        $stompFrame = new Frame();
        $connectFrame = $stompFrame->setLogin($this->ss['login'], $this->ss['password'])
            ->setHeartBeat(0, 10000)->getConnect();
        $subscribeFrame = $stompFrame->getSubscribe($this->ss['queue']);
        $client = new Client($this->ss['host']);
        $client->text($connectFrame);
        $client->text($subscribeFrame);

You sure the way to inject the suscribe queue is using $client=text('name of queue')

Please any advice more than welcome

@jeeinn
Copy link
Owner

jeeinn commented Jan 18, 2023

This project just wrapping the stompFrame format.
Over ws(s):// is dependent on this repo: https://github.com/Textalk/websocket-php#client

Maybe you should check the connect URL, such as starting with wss:// and ending with the port :443
The protocol version and queue name also needs to be checked

@eduardo-g-silva
Copy link
Author

Hi Jeeinn, tanks a lot to answer I have being trying all sort of things to make this work.

I have a sample in js that works with the same url and queue but i need to implement this in php.

The connection it is fine so I think is not about the url, credentials or port.
Olso if i change any of this values I get an error: " Could not open socket"

When I do the while i get the message with the correct response but with null body


        while (true) {
            try {
                $message = $client->receive();
                $this->logger($this::INFO, 'STOMP full response: ' . $message);

[2023-01-18T09:47:41.401761+00:00] wl-nns-dev.INFO: STOMP full response: CONNECTED server:ActiveMQ/5.11.0.redhat-630516 heart-beat:10000,0 session:ID:broker-amq-2-5-nxhq9-43521-1671455839478-5:3070 version:1.2 [] []

And then after parser:
[2023-01-18T09:47:41.401941+00:00] wl-nns-dev.INFO: STOMP after parser: {"command":"CONNECTED","headers":{"server":"ActiveMQ/5.11.0.redhat-630516","heart-beat":"10000,0","session":"ID:broker-amq-2-5-nxhq9-43521-1671455839478-5:3070","version":"1.2"},"body":null} []

But i allways get null in the body.

@eduardo-g-silva
Copy link
Author

Finaly manage to make it work:

The way that it is sending the credentials and the queue it is perfect

looks like we need to wait a bit to get the next call.

    public function getStompMessage(): array
    {
        $stompFrame = new Frame();
        $connectFrame = $stompFrame->setLogin($this->ss['login'], $this->ss['password'])
            ->setHeartBeat(0, 10000)->getConnect();
        $subscribeFrame = $stompFrame->getSubscribe($this->ss['queue']);
        $client = new Client($this->ss['host']);
        $client->text($connectFrame);
        $client->text($subscribeFrame);
        $response = [];
        $i = 0;
        while ($i < 3) {
            echo".";
            sleep(5);
            try {
                $message = $client->receive();
                if (empty($message) || in_array($message, self::BYTE)) {
                    $i++;
                    continue;
                }
                $parsed = $stompFrame->parser($message);
                if ($parsed['command'] == $this::STOMP_COMMAND_ERROR) {
                    $this->logger($this::INFO, 'STOMP return with ERROR command:', $parsed['body']);
                    $client->close();
                    break;
                }
                if (($parsed['command'] == $this::STOMP_COMMAND_MESSAGE) || ($parsed['body'])) {
                        return json_decode($parsed['body'], true);
                }
            } catch (Exception $e) {
                $this->logger($this::ERROR, 'STOMP error', (array)$e->getMessage());
            }
            $i++;
        }
        return $response;
    }

@jeeinn jeeinn pinned this issue Jan 30, 2023
@jeeinn jeeinn added the good first issue Good for newcomers label Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants