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

Can't consume messages #199

Open
goncalo-almeida-mc opened this issue Sep 16, 2021 · 3 comments
Open

Can't consume messages #199

goncalo-almeida-mc opened this issue Sep 16, 2021 · 3 comments

Comments

@goncalo-almeida-mc
Copy link

I'm running dart_amqp libs to enable RabbitMQ communication on my Flutter app.

I don't know for sure if the faulty side is on flutter-pi but when running on the main machine it works and Flutter consumes the Rabbit messages.
I just tried to validate the app on my RPI and turns out the screen doesn't update according to the messages that are being sent, meaning it isn't consuming the messages.

Internally on RPI, I can send and receive the messages, so maybe it is some issue from flutter-pi?

Version: 2.2.3 on both ends

@ardera
Copy link
Owner

ardera commented Sep 16, 2021

Sounds very unlikely to be a flutter-pi issue.
Flutter-pi just provides flutter with graphics output / user input (+ some other stuff, but nothing related to what you're doing). I've also never heard of RabbitMQ or dart_ampq, so I'm afraid I can't help you with that

If you have a minimal code sample that reproduces the issue, which works on other devices but not on pi using flutter-pi I'd be happy to look at it, but generally speaking, this doesn't sound like a flutter-pi issue

@goncalo-almeida-mc
Copy link
Author

Thanks!

To install the RMQ server:
$ sudo apt-get install rabbitmq-server
$ sudo systemctl enable rabbitmq-server

To start it:
$ sudo service rabbitmq-server start
$ sudo rabbitmqctl start_app

To stop it:
$ sudo rabbitmqctl stop_app
$ sudo service rabbitmq-server stop

You can try with the attached zipped python scripts to send (and receive, just to check it is actually being sent) and the code below to consume on Flutter, I think I didn't forget anything :)
send-receive.tar.gz

- - Flutter code - -
import "package:dart_amqp/dart_amqp.dart";

void recvMsg() async {

String queueName = 'hello';
List<String> routingKeys = [queueName];
Client client = Client();
// auto-connect to localhost:5672 using guest credentials
Channel channel = await client.channel();
Exchange exchange = await channel.exchange(queueName, ExchangeType.DIRECT);
Consumer consumer = await exchange.bindQueueConsumer(queueName, routingKeys);

consumer.listen((AmqpMessage message) {
  // Get the payload as a string
  print(" [x] Received string: ${message.payloadAsString}");

  /*
  // Or unserialize to json
  print(" [x] Received json: ${message.payloadAsJson}");

  // Or just get the raw data as a Uint8List
  print(" [x] Received raw: ${message.payload}");
  */

  // The message object contains helper methods for
  // replying, ack-ing and rejecting
  message.ack();
});

}

@goncalo-almeida-mc
Copy link
Author

I store that ${message.payloadAsString} on a String variable that I am displaying on screen, so I know for sure it isn't being consume (as Pi only shows screen app).

Through ssh it also isn't printing any message on terminal.

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