/// <summary> /// Creates a new exchange subscription. /// </summary> /// <param name="name">The name to give the subscription.</param> /// <param name="exchangeName">The name of the exchange to subscribe to.</param> /// <param name="exchangeType">The type of exchange to subscribe to.</param> /// <param name="routingKey">The exchange routing key if any.</param> /// <param name="handler">The message received handler to use with the subscription.</param> public UnityAmqpExchangeSubscription(string name, string exchangeName, AmqpExchangeTypes exchangeType, string routingKey, AmqpExchangeMessageReceivedEventHandler handler, UnityAction <AmqpExchangeSubscription, IAmqpReceivedMessage> unityHandler) : base(name, exchangeName, exchangeType, routingKey, handler) { OnMessageReceived = new AmqpExchangeMessageReceivedUnityEvent(); OnMessageReceived.AddListener(unityHandler); }
/// <summary> /// Creates a new exchange subscription. /// </summary> /// <param name="name">The name to give the subscription.</param> /// <param name="exchangeName">The name of the exchange to subscribe to.</param> /// <param name="exchangeType">The type of exchange to subscribe to.</param> /// <param name="routingKey">The exchange routing key if any.</param> /// <param name="handler">The message received handler to use with the subscription.</param> public AmqpExchangeSubscription(string name, string exchangeName, AmqpExchangeTypes exchangeType, string routingKey, AmqpExchangeMessageReceivedEventHandler handler) { if (string.IsNullOrEmpty(exchangeName)) { throw new ArgumentNullException("exchangeName"); } Name = name; Enabled = true; // default to enabled ExchangeName = exchangeName; ExchangeType = exchangeType; Handler = handler; RoutingKey = routingKey != null ? routingKey : ""; // routing key cannot be null }
// Use this for initialization void Start() { serverTerhubung = false; //inisialisasi properti koneksi requestExchange = "TheDemiteRequestExchange"; requestRoutingKey = "TheDemiteRequestRoutingKey"; responseExchange = "TheDemiteResponseExchange"; responseRoutingKey = "TheDemiteResponseRoutingKey"; responExchangeType = AmqpExchangeTypes.Direct; //connect to rabitmq server AmqpClient.Instance.Connection = "ITB"; AmqpClient.Connect(); AmqpClient.Instance.OnConnected.AddListener(HandleConnected); }
// Use this for initialization void Start() { serverConnected = false; // initialize connection properties requestExchangeName = "DigipetRequestExchange"; requestRoutingKey = "DigipetRequestRoutingKey"; responseExchangeName = "DigipetResponseExchange"; responseRoutingKey = "DigipetResponseRoutingKey"; responseExchangeType = AmqpExchangeTypes.Direct; // connect to rabbitmq server AmqpClient.Instance.Connection = "ITB"; //AmqpClient.Instance.Connection = "localhost"; AmqpClient.Connect(); // handle event after connected to rabbitmq server AmqpClient.Instance.OnConnected.AddListener(HandleConnected); }
/// <summary> /// Creates a new exchange subscription. /// </summary> /// <param name="exchangeName">The name of the exchange to subscribe to.</param> /// <param name="exchangeType">The type of exchange to subscribe to.</param> /// <param name="routingKey">The exchange routing key if any.</param> /// <param name="handler">The message received handler to use with the subscription.</param> /// <param name="unityHandler">The Unity message received handler to use with the subscription.</param> public UnityAmqpExchangeSubscription(string exchangeName, AmqpExchangeTypes exchangeType, string routingKey, AmqpExchangeMessageReceivedEventHandler handler, UnityAction <AmqpExchangeSubscription, IAmqpReceivedMessage> unityHandler) : this("Unity Exchange Subscription", exchangeName, exchangeType, routingKey, handler, unityHandler) { }
static void Main(string[] args) { try { if (args.Length == 0) { PrintUsage(args); return; } #region Prepare Arguments // Parse arguments and assign values foreach (var arg in args) { if (!arg.Contains(":")) { PrintUsage(args); return; } var parsedArg = arg.SplitClean(':'); var name = parsedArg[0]; var value = parsedArg[1]; switch (name) { case "server": server = value; break; case "port": port = int.Parse(value); break; case "api": api = int.Parse(value); break; case "vhost": virtualHost = value; break; case "u": case "user": case "username": username = value; break; case "p": case "pass": case "password": password = value; break; case "reconnect": reconnectInterval = short.Parse(value); break; case "heartbeat": requestedHeartbeat = ushort.Parse(value); break; case "cmd": case "command": command = value; break; case "exchange": exchangeName = value; break; case "type": exchangeType = (AmqpExchangeTypes)Enum.Parse(typeof(AmqpExchangeTypes), value, true); break; case "queue": queueName = value; break; case "key": case "routing": case "routingkey": routingKey = value; break; case "count": count = byte.Parse(value); break; } } #endregion Prepare Arguments #region Validate Arguments if (!commands.Contains(command)) { PrintUsage(args); return; } #endregion Validate Arguments // Create a new client using the supplied arguments client = AmqpConnectionFactory.Create(server, port, api, virtualHost, username, password, reconnectInterval, requestedHeartbeat); // Hook up event handlers client.Blocked += Client_Blocked; client.Connected += Client_Connected; client.Disconnected += Client_Disconnected; client.ConnectionAborted += Client_ConnectionAborted; // If this is an AMQP operation, connect if (command == "rx" || command == "tx") { Console.WriteLine("Connecting to: {0}", AmqpHelper.GetConnectionInfo(client)); Console.WriteLine("Press enter to exit"); client.Connect(); Console.ReadLine(); client.Disconnect(); } // Otherwise this is a REST API operation so execute it else { if (command == "exchanges") { Console.WriteLine("Listing exchanges for {0}:{1} and virtual host '{2}'", server, api, virtualHost); foreach (var exchange in client.GetExchanges(virtualHost)) { Console.WriteLine("name:{0}, type:{1}, auto delete:{2}, durable:{3}", exchange.Name, exchange.Type.ToString().ToLower(), exchange.AutoDelete, exchange.Durable); } } else if (command == "queues") { Console.WriteLine("Listing queues for {0}:{1} and virtual host '{2}'", server, api, virtualHost); foreach (var queue in client.GetQueues(virtualHost)) { Console.WriteLine("name:{0}, auto delete:{1}, durable:{2}, state:{3}, policy:{4}, exclusive:{5}", queue.Name, queue.AutoDelete, queue.Durable, queue.State, queue.Policy, queue.ExclusiveConsumerTag); } } } } catch (Exception ex) { Console.WriteLine("{0}", ex); //Console.ReadLine(); Environment.Exit(-1); } }
/// <summary> /// Creates a new exchange subscription. /// </summary> /// <param name="exchangeName">The name of the exchange to subscribe to.</param> /// <param name="exchangeType">The type of exchange to subscribe to.</param> /// <param name="routingKey">The exchange routing key if any.</param> /// <param name="handler">The message received handler to use with the subscription.</param> public AmqpExchangeSubscription(string exchangeName, AmqpExchangeTypes exchangeType, string routingKey, AmqpExchangeMessageReceivedEventHandler handler) : this("Exchange Subscription", exchangeName, exchangeType, routingKey, handler) { }