Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using System.Text;
- using UnityEngine;
- using RabbitMQ.Client;
- using RabbitMQ.Client.Events;
- public class Test : MonoBehaviour
- {
- public ConnectionFactory connectionFactory;
- public IConnection connection;
- public IModel channel;
- private bool isReceiving = false;
- string host = "cloudrmqserver.pptik.id";
- int port = 5672;
- string user = "tmdgdai";
- string pass = "tmdgdai";
- string vhost = "/tmdgdai";
- string queue_name = "TestUnity";
- // Start is called before the first frame update
- void Start()
- {
- connectionFactory = new ConnectionFactory();
- connectionFactory.HostName = host;
- //connectionFactory.Port = port;
- connectionFactory.UserName = user;
- connectionFactory.Password = pass;
- connectionFactory.VirtualHost = vhost;
- connection = connectionFactory.CreateConnection();
- Debug.Log("Koneksi " + (connection.IsOpen ? "Berhasil!" : "Gagal!"));
- }
- // Update is called once per frame
- void LateUpdate()
- {
- using (channel = connection.CreateModel())
- {
- channel.QueueDeclare(queue: queue_name,
- durable: true,
- exclusive: false,
- autoDelete: false,
- arguments: null);
- var consumer = new EventingBasicConsumer(channel);
- consumer.Received += (model, ea) =>
- {
- Debug.Log("[x] Pesan diterima: " + Encoding.UTF8.GetString(ea.Body.ToArray()));
- };
- channel.BasicConsume(queue: queue_name,
- autoAck: true,
- consumer: consumer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement