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

help newbie #99

Closed
artem-webdev opened this issue Dec 26, 2019 · 6 comments
Closed

help newbie #99

artem-webdev opened this issue Dec 26, 2019 · 6 comments

Comments

@artem-webdev
Copy link

artem-webdev commented Dec 26, 2019

I can not understand why the subscription does not work

let centrifuge = new Centrifuge('ws://localhost:8000/connection/websocket');
centrifuge.setToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0MiJ9.jSjZK6C_SQXVMD_SKU7ZEAa39SKRJtDa4A26uE9Q6EI");

centrifuge.on('connect', function (context) {
    console.log(context);
});
centrifuge.on('disconnect', function (context) {
    console.log(context);
});

let subscription = centrifuge.subscribe("chat", function (message) {
    console.log(message);
});

subscription.on("subscribe", function (context) {
    console.log(context);
});
centrifuge.connect();

this code gives no errors and the subscription does not work

I can not understand what is the reason in centrifugo server or in centrifuge-js

here the server config it is very simple

{
  "history_recover": true,
  "admin_password": "8fe61ef2-23bd-4520-9892-0658709140df",
  "admin_secret": "2db56574-4978-4dd6-bc6a-e6cab276ac6d",
  "api_key": "1a64664d-1205-4b61-8bf4-34c2a0d3a881",
  "secret": "4a56ed9c-37a1-4fdb-8b9d-4067b9a47fe0",
}

run from the working directory

./centrifugo --admin

push example

import requests
import json

command = {
    "method": "publish",
    "params": {
        "channel": "chat",
        "data": {
            "message": "test-message"
        }
    }
}

api_key = "1a64664d-1205-4b61-8bf4-34c2a0d3a881"
data = json.dumps(command)
headers = {'Content-type': 'application/json', 'Authorization': 'apikey ' + api_key}
resp = requests.post("http://localhost:8000/api", data=data, headers=headers)
print(resp.json())

there are no errors from the server side

@FZambia
Copy link
Member

FZambia commented Dec 26, 2019

@artem-webdev hello!

history_recover does not work without history_size and history_lifetime set (see docs)- at moment this misconfiguration results in suppressing message sending. You have two options:

Use config like this:

{
  "admin_password": "8fe61ef2-23bd-4520-9892-0658709140df",
  "admin_secret": "2db56574-4978-4dd6-bc6a-e6cab276ac6d",
  "api_key": "1a64664d-1205-4b61-8bf4-34c2a0d3a881",
  "secret": "4a56ed9c-37a1-4fdb-8b9d-4067b9a47fe0"
}

Or config like this:

{
  "history_recover": true,
  "history_size": 10,
  "history_lifetime": 60,
  "admin_password": "8fe61ef2-23bd-4520-9892-0658709140df",
  "admin_secret": "2db56574-4978-4dd6-bc6a-e6cab276ac6d",
  "api_key": "1a64664d-1205-4b61-8bf4-34c2a0d3a881",
  "secret": "4a56ed9c-37a1-4fdb-8b9d-4067b9a47fe0"
}

Misconfiguration like this must be actually checked on Centrifugo start to prevent silent failures you experienced - I will try to add this check into Centrifugo server in future releases.

@artem-webdev
Copy link
Author

I put the library through NPM
npm install centrifuge

connected in vuejs
nothing worked, apparently this version for some reason does not fit

version with cdn earned

@artem-webdev
Copy link
Author

artem-webdev commented Dec 27, 2019

I'm sorry, maybe I missed something but message recovery doesn’t work for me

maybe something else needs to be installed in the client?

<html lang="en">
<head>
    <meta charset="utf-8">
    <title>centrifuge</title>
    <script src="https://cdn.rawgit.com/centrifugal/centrifuge-js/2.3.0/dist/centrifuge.min.js"></script>
</head>
<body>

<script>

    const centrifuge = new Centrifuge('ws://localhost:8000/connection/websocket');
    centrifuge.setToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0MiJ9.jSjZK6C_SQXVMD_SKU7ZEAa39SKRJtDa4A26uE9Q6EI");

    const subscription = centrifuge.subscribe("chat", function (message) {
        console.log(message);
    });

    subscription.on("centrifugo", function (context) {
        console.log(context);
    });

    centrifuge.on('connect', function (context) {
        console.log(context);
    });

    centrifuge.on('disconnect', function (context) {
        console.log(context);
    });

    centrifuge.connect();

</script>

</body>
</html>

config server

{
  "history_recover": true,
  "history_size": 10000,
  "history_lifetime": 3600,
  "admin_password": "8fe61ef2-23bd-4520-9892-0658709140df",
  "admin_secret": "2db56574-4978-4dd6-bc6a-e6cab276ac6d",
  "api_key": "1a64664d-1205-4b61-8bf4-34c2a0d3a881",
  "secret": "4a56ed9c-37a1-4fdb-8b9d-4067b9a47fe0"
}

@FZambia
Copy link
Member

FZambia commented Dec 28, 2019

Please describe what you expect to see and what you see instead

@artem-webdev
Copy link
Author

from message recovery, I expect that when the subscriber falls off, after reconnecting he will receive missed messages

@FZambia
Copy link
Member

FZambia commented Mar 29, 2020

The fix that does not allow to start Centrifugo without proper configuration of history already released so I think this can be closed.

@FZambia FZambia closed this as completed Mar 29, 2020
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

2 participants