Я пытаюсь использовать очередь rabbitMq и добавить сообщение к TextView
, но получаю эту ошибку:
java.net.ConnectException:failed to connect to to /127.0.0.1(port 5672) from/127.0.0.1(port 49582)after 6000ms:isConnected failed:ECONNREFUSED(Connection refused)
.
Я новичок в android и я не знаю, что делать.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String QUEUE_NAME = "Invitation2";
TextView tv = findViewById(R.id.ident);
Thread thread = new Thread(new Runnable(){
public void run(){
try {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), "UTF-8");
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
tv.append(message);
}
});
}catch (Exception e){
Log.i("error", e.toString());
}
};
channel.basicConsume(QUEUE_NAME, true, deliverCallback, consumerTag -> { });
}catch (Exception e){
Log.i("error", e.toString());
}
}
});
thread.start();
}