public void Start() { // Load the config file from StreamingAssets. string configText = ""; bool configError = false; try { configText = File.ReadAllText(Path.Combine(Application.streamingAssetsPath, CONFIG_FILE)); } catch { configError = true; } if (string.IsNullOrEmpty(configText)) { configError = true; } var amqpConnection = new AmqpConnection(); if (!configError) { var config = StompConfig.ConvertToObject(configText); amqpConnection.Name = "StompConfig"; amqpConnection.Host = "localhost"; amqpConnection.AmqpPort = 5672; // int.Parse(config.port); amqpConnection.Username = "******"; //config.username; amqpConnection.Password = "******"; //config.password; amqpConnection.VirtualHost = vhost; //config.virtual_host; amqpConnection.WebPort = 15674; amqpConnection.ReconnectInterval = 5; amqpConnection.RequestedHeartBeat = 30; } else { print("ERROR : Config file invalid!!!!!!!!"); } AmqpClient.AddConnection(amqpConnection); client = GetComponent <AmqpClient>(); client.enabled = true; client.Connection = amqpConnection.Name; client.ConnectToHost(); _watson_listener = GetComponent <WatsonListener>(); }
void restartAction() { AmqpController.amqpControl.exchangeSubscription.Handler = ProcessRestart; RestartRequest json = new RestartRequest(); json.id = id; json.type = "restart"; json.username = PlayerPrefs.GetString("username"); string request = JsonUtility.ToJson(json); AmqpClient.Publish(AmqpController.amqpControl.requestExchangeName, AmqpController.amqpControl.requestRoutingKey, request); }
// Handles a connection event void HandleConnected(AmqpClient client) { SensorData data = new SensorData { id = sensorId, family = sensorFamily, value = sensorValue, type = "add" }; string json = JsonUtility.ToJson(data); amqp.PublishToExchange("sensorData", "", json); }
public void OnConnected(AmqpClient client) { Debug.Log("OnConnected"); Debug.Log("isConnected?" + AmqpClient.Instance.IsConnected); AmqpClient.DeclareQueue("Test"); AmqpQueue[] qs = AmqpClient.Instance.GetQueueList(); foreach (AmqpQueue q in qs) { Debug.Log(q.Name); } }
public void ChangeAction() { warning.text = ""; InputField inputOld = GameObject.Find("OldPassInputField").GetComponent <InputField>(); InputField inputNew = GameObject.Find("NewPassInputField").GetComponent <InputField>(); InputField inputRetype = GameObject.Find("RetypePassInputField").GetComponent <InputField>(); string old = inputOld.text; string newPass = inputNew.text; string retype = inputRetype.text; if (old == "") { warning.text = "Please fill in old password"; } if (newPass == "") { warning.text = "Please fill in new password"; } if (retype == "") { warning.text = "Please retype new password"; } if (old != "" && newPass != "" && retype != "") { if (newPass == retype) { AmqpController.amqpControl.exchangeSubscription.Handler = ProcessChangePass; ChangePassJson json = new ChangePassJson(); json.id = id; json.type = "changepassword"; json.username = PlayerPrefs.GetString("username"); json.oldPass = old; json.newPass = newPass; string request = JsonUtility.ToJson(json); AmqpClient.Publish(AmqpController.amqpControl.requestExchangeName, AmqpController.amqpControl.requestRoutingKey, request); } else { warning.text = "Retype password is different from new password"; } } }
public void BasicQos() { int prefetchSize, prefetchCount; if (!int.TryParse(PrefetchSize.text, out prefetchSize)) { prefetchSize = 0; } if (!int.TryParse(PrefetchCount.text, out prefetchCount)) { prefetchCount = 0; } AmqpClient.BasicQos((uint)prefetchSize, (ushort)prefetchCount, PrefetchGlobal.isOn); }
// *Note*: Only interact with the AMQP library in Start(), not Awake() // since the AmqpClient initializes itself in Awake() and won't be ready yet. public override void Start() { // Create a new exchange subscription using the inspector values var Input_subscription = new AmqpExchangeSubscription(ExchangeName, ExchangeType, InputRoutingKey, HandleInputMessageReceived); //var Output_subscription = new AmqpExchangeSubscription(ExchangeName, ExchangeType, OutputRoutingKey, HandleInputMessageReceived); /* * Add the subscription to the client. If you are using multiple AmqpClient instances then * using the static methods won't work. In that case add a inspector property of type 'AmqpClient' * and assigned a reference to the connection you want to work with and call the 'SubscribeToExchange()' * non-static method instead. */ AmqpClient.Subscribe(Input_subscription); Debug.LogFormat("Anttena subscribed to {0}", Input_subscription); }
void ReturnHome() { GameObject mapController = GameObject.Find("Map"); var mapScript = mapController.GetComponent <MapController>(); MapToHomeRequest request = new MapToHomeRequest(); request.id = mapScript.uniqueId; request.type = "maptohome"; request.username = PlayerPrefs.GetString("username"); request.tileX = mapScript.tileX; request.tileY = mapScript.tileY; string jsonRequest = JsonUtility.ToJson(request); AmqpClient.Publish(AmqpControllerScript.amqpControl.requestExchange, AmqpControllerScript.amqpControl.requestRoutingKey, jsonRequest); }
// Handles a disconnection event void HandleDisconnected(AmqpClient client) { Connection.interactable = true; ConnectButton.interactable = true; DisconnectButton.interactable = false; ExchangeName.interactable = false; RoutingKey.interactable = false; SubscribeButton.interactable = false; UnsubscribeButton.interactable = false; PublishButton.interactable = false; PublishExchange.interactable = false; PublishMessage.interactable = false; PublishRoutingKey.interactable = false; }
public void PanelTareaClose() { //cuando cierro el panel actualizo el modelo tarea.addAtributo("prioridad", prioridad.transform.GetComponent <Text>().text); if ((this.extraerAtributoDeFecha("Año") != 0) && (extraerAtributoDeFecha("Mes") != 0) && (extraerAtributoDeFecha("Dia") != 0)) { tarea.addAtributo("fecha", new DateTime(Convert.ToInt32(this.extraerAtributoDeFecha("Año")), Convert.ToInt32(this.extraerAtributoDeFecha("Mes")), Convert.ToInt32(this.extraerAtributoDeFecha("Dia")))); } Debug.Log("salio"); PanelTarea.SetActive(false); isOpen = false; String message = String.Format("{{\"user_id\": \"{0}\", \"value\": {1}}}", Actor.actual.getId(), (DateTime.Now - timeOpen).Seconds); AmqpClient.Publish("topic_logs", "TiempoLecturaUserStory", message); }
void GiveFood() { if (!foodEnabled && !ballInGround) { GameObject mainCam = GameObject.FindGameObjectWithTag("MainCamera"); GameObject food = GameObject.CreatePrimitive(PrimitiveType.Cube); food.tag = "Food"; food.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); food.transform.position = new Vector3(mainCam.transform.parent.position.x, 0, mainCam.transform.parent.position.z); Rigidbody foodRigibody = food.AddComponent <Rigidbody>(); foodRigibody.mass = 1; foodRigibody.isKinematic = true; foodEnabled = true; // update position in server var mapScript = mapController.GetComponent <MapController>(); int tileX = mapScript.tileX; int tileY = mapScript.tileY; bool readyToSend = mapScript.okToSentPetPos; if (readyToSend) { timeStartMove = DateTime.Now.Ticks.ToString(); UpdatePetPos petPos = new UpdatePetPos(); petPos.type = "listplayer"; petPos.username = PlayerPrefs.GetString("username"); petPos.timeStartMove = timeStartMove; petPos.petLastPosX = transform.position.x; petPos.petLastPosY = transform.position.z; petPos.petPosX = food.transform.position.x; petPos.petPosY = food.transform.position.z; petPos.tileX = tileX; petPos.tileY = tileY; petPos.petState = "walkFood"; petPos.speed = speed; string requestJson = JsonUtility.ToJson(petPos); AmqpClient.Publish(AmqpController.amqpControl.requestExchangeName, AmqpController.amqpControl.requestRoutingKey, requestJson); } petCalled = false; } }
private static void SimulateNetworkFailure(ServiceBusClient client) { var connection = client.Connection; AmqpClient amqpClient = (AmqpClient)typeof(ServiceBusConnection).GetField( "_innerClient", BindingFlags.Instance | BindingFlags.NonPublic) .GetValue(connection); AmqpConnectionScope scope = (AmqpConnectionScope)typeof(AmqpClient).GetProperty( "ConnectionScope", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(amqpClient); ((FaultTolerantAmqpObject <AmqpConnection>) typeof(AmqpConnectionScope).GetProperty( "ActiveConnection", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(scope)).TryGetOpenedObject(out AmqpConnection activeConnection); typeof(AmqpConnection).GetMethod("AbortInternal", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(activeConnection, null); }
//transfer messages in update public override void Update() { inputInfo.CurrentHealth = transform.parent.GetComponent <Health>().health; // CentralBus.SightChannel.AddListener(updateCreatureInsight); //publish out creature info List <int> inputArray = WrapInput2Array(inputInfo); string json = JsonUtility.ToJson(inputInfo); AmqpClient.Publish(ExchangeName, OutputRoutingKey, json); if (Time.time >= nextTime) { //mock Recieved output MockProcess(inputInfo); nextTime += interval; } }
public AmqpSink(AmqpConfiguration amqpConfig, IConnection amqpConnection, ITextFormatter textFormatter, IFormatProvider formatProvider) { this._amqpConfig = amqpConfig; this._amqpClient = new AmqpClient(); this._connection = amqpConnection; if (amqpConfig.IsRpc) { this._amqpClient.InitiateAmqpRpc(this._connection); this._rpcClient = this._amqpClient.CreateAmqpRpcClient(amqpNode: this._amqpConfig.QueueName); } else { this._amqpSession = amqpConnection.CreateSession(); this._amqpSender = this._amqpSession.CreateSender(name: "Amqp-Serilog.Sinks.Amqp", address: this._amqpConfig.QueueName); } this._textFormatter = textFormatter; this._formatProvider = formatProvider; }
void MoveBehaviour() { if (!foodEnabled && !ballInGround && !petCalled) { var mapScript = mapController.GetComponent <MapController>(); int tileX = mapScript.tileX; int tileY = mapScript.tileY; bool readyToSend = mapScript.okToSentPetPos; if (Vector3.Distance(targetMove, transform.position) < 0.1f && readyToSend) { RandomTargetPos(); timeStartMove = DateTime.Now.Ticks.ToString(); UpdatePetPos petPos = new UpdatePetPos(); petPos.type = "listplayer"; petPos.username = PlayerPrefs.GetString("username"); petPos.timeStartMove = timeStartMove; petPos.petLastPosX = 0f; petPos.petLastPosY = 0f; petPos.petPosX = targetMove.x; petPos.petPosY = targetMove.z; petPos.tileX = tileX; petPos.tileY = tileY; petPos.petState = "walk"; petPos.speed = speed; string requestJson = JsonUtility.ToJson(petPos); AmqpClient.Publish(AmqpController.amqpControl.requestExchangeName, AmqpController.amqpControl.requestRoutingKey, requestJson); } Vector3 lookpos = targetMove - transform.position; lookpos.y = 0; if (lookpos != Vector3.zero) { var rotation = Quaternion.LookRotation(lookpos); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 2.0f); } transform.position = Vector3.MoveTowards(transform.position, targetMove, Time.deltaTime * speed); } }
public void MultiAckMessage() { try { AmqpClient.BasicAck(message.DeliveryTag, true); var payload = System.Text.Encoding.UTF8.GetString(message.Body); AmqpConsole.Color = new Color(1f, 0.5f, 0); AmqpClient.Log("This message (and all previous unacknowledged ones) were acknowledged: " + payload); AmqpConsole.Color = null; } catch (Exception ex) { AmqpConsole.Color = new Color(1f, 0.5f, 0); AmqpClient.Log("ERROR: " + ex.Message); AmqpConsole.Color = null; } Background.color = new Color32(45, 210, 39, 81); }
// update latitude and longitude value and send the request to server through rabbitmq void UpdateGpsAndSendRequest() { //this.latitude = Input.location.lastData.latitude; //this.longitude = Input.location.lastData.longitude; //posText.text = "lat= " + this.latitude + " --- Long=" + this.longitude; if (this.lastLatitude != this.latitude || this.lastLongitude != this.longitude) { this.lastLatitude = this.latitude; this.lastLongitude = this.longitude; Debug.Log("publish map"); string requestJSON = this.CreateJsonMassage("map"); AmqpClient.Publish(AmqpControllerScript.amqpControl.requestExchange, AmqpControllerScript.amqpControl.requestRoutingKey, requestJSON); this.mapAcquiredAndProcessed = false; } }
// 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); }
//float temperature; //float humidity; //float CO2; // Start is called before the first frame update void Start() { amqp = this.gameObject.AddComponent <AmqpClient>(); amqp.OnConnected = new AmqpClientUnityEvent(); amqp.OnDisconnected = new AmqpClientUnityEvent(); amqp.OnReconnecting = new AmqpClientUnityEvent(); amqp.OnBlocked = new AmqpClientUnityEvent(); amqp.OnSubscribedToExchange = new AmqpExchangeSubscriptionUnityEvent(); amqp.OnUnsubscribedFromExchange = new AmqpExchangeSubscriptionUnityEvent(); amqp.OnConnected.AddListener(HandleConnected); amqp.OnDisconnected.AddListener(HandleDisconnected); amqp.OnReconnecting.AddListener(HandleReconnecting); amqp.OnBlocked.AddListener(HandleBlocked); amqp.OnSubscribedToExchange.AddListener(HandleExchangeSubscribed); amqp.OnUnsubscribedFromExchange.AddListener(HandleExchangeUnsubscribed); amqp.Connection = "localhost"; amqp.ConnectToHost(); // Uncomment to create new seating plan // Serialize(newSeatingPlan, "Assets/SeatingPlans/conway.sp"); var ledRows = display.gameObject.transform.Find("LEDs"); var seatRows = seat_rows.gameObject.transform; // Build arrays to access chairs and seating display for (int i = 0; i < 19; i++) { var seatRow = seatRows.GetChild(i); var ledRow = ledRows.GetChild(i); for (int j = 0; j < 14; j++) { chairs[i, j] = seatRow.gameObject.transform.GetChild(j).GetComponent <Chair>(); displayLEDs[i, j] = ledRow.gameObject.transform.GetChild(j).GetComponent <Led>(); occupancie[i, j] = false; } } // Wait for objects to be loaded before loading first seating plan StartCoroutine(WaitForLoading()); }
public void UnsubscribeQueue() { Debug.Log("UnsubscribeQueue"); var queueName = SubscribeQueueName.text; foreach (var sub in queueSubscriptions) { if (sub.QueueName == queueName) { AmqpClient.Unsubscribe(sub); AmqpConsole.Color = new Color(0f, 1f, 0); AmqpConsole.WriteLineFormat("Unsubscribed for queue {0}", sub.QueueName); AmqpConsole.Color = null; return; } } AmqpConsole.Color = new Color(1f, 0f, 0); AmqpConsole.WriteLineFormat("NO Subscription exists for queue {0}", queueName); AmqpConsole.Color = null; }
// *Note*: Only interact with the AMQP library in Start(), not Awake() // since the AmqpClient initializes itself in Awake() and won't be ready yet. public override void Start() { InputRoutingKey = ExchangeName + ".Input." + MyId; OutputRoutingKey = ExchangeName + ".Output." + MyId; inputInfo.ID = MyId; inputInfo.HeardMessage = new List <int>(new int[] { 0, 0 });; // Create a new exchange subscription using the inspector values //var Output_subscription = new AmqpExchangeSubscription(ExchangeName, ExchangeType, OutputRoutingKey, HandleInputMessageReceived); /* * Add the subscription to the client. If you are using multiple AmqpClient instances then * using the static methods won't work. In that case add a inspector property of type 'AmqpClient' * and assigned a reference to the connection you want to work with and call the 'SubscribeToExchange()' * non-static method instead. */ AmqpClient.Subscribe(new AmqpExchangeSubscription(ExchangeName, ExchangeType, InputRoutingKey, HandleInputMessageReceived)); //Debug.LogFormat("subscribed to {0}", Input_subscription); CentralBus.HeardMessage.AddListener(HeardMessage); }
public void SubscribeQueue() { Debug.Log("SubscribeQueue"); var queueName = SubscribeQueueName.text; // Ensure this subscription doesn't already exist foreach (var sub in queueSubscriptions) { if (sub.QueueName == queueName) { AmqpConsole.Color = new Color(1f, 0.5f, 0); AmqpConsole.WriteLineFormat("Subscription already exists for queue {0}", queueName); AmqpConsole.Color = null; return; } } var subscription = new UnityAmqpQueueSubscription(SubscribeQueueName.text, true, null, UnityEventDebugQueueMessageHandler); AmqpClient.Subscribe(subscription); }
// Start is called before the first frame update void Start() { amqp = this.gameObject.AddComponent <AmqpClient>(); amqp.OnConnected = new AmqpClientUnityEvent(); amqp.OnDisconnected = new AmqpClientUnityEvent(); amqp.OnReconnecting = new AmqpClientUnityEvent(); amqp.OnBlocked = new AmqpClientUnityEvent(); amqp.OnSubscribedToExchange = new AmqpExchangeSubscriptionUnityEvent(); amqp.OnUnsubscribedFromExchange = new AmqpExchangeSubscriptionUnityEvent(); amqp.OnConnected.AddListener(HandleConnected); amqp.OnDisconnected.AddListener(HandleDisconnected); amqp.OnReconnecting.AddListener(HandleReconnecting); amqp.OnBlocked.AddListener(HandleBlocked); amqp.OnSubscribedToExchange.AddListener(HandleExchangeSubscribed); amqp.OnUnsubscribedFromExchange.AddListener(HandleExchangeUnsubscribed); amqp.Connection = "localhost"; amqp.WriteToConsole = false; amqp.ConnectToHost(); }
void CobaInsert() { int iduser = 50; int iditem = 60; int itemtotal = 110; AmqpControllerScript.amqpControl.exchangeSubscription.Handler = ProcessCoba; RequestJson request = new RequestJson(); request.id = id; request.type = "insertdata"; request.iduser = iduser; request.iditem = iditem; request.itemtotal = itemtotal; string requestJson = JsonUtility.ToJson(request); Debug.Log(requestJson); AmqpClient.Publish(AmqpControllerScript.amqpControl.requestExchange, AmqpControllerScript.amqpControl.requestRoutingKey, requestJson); }
public void BasicAck() { if (queueMessages.Count > 0) { var msg = queueMessages.Dequeue(); try { AmqpClient.BasicAck(msg.DeliveryTag, false); var payload = System.Text.Encoding.UTF8.GetString(msg.Body); AmqpConsole.Color = new Color(1f, 0.5f, 0); AmqpClient.Log("Message acknowledged: " + payload); AmqpConsole.Color = null; } catch (Exception ex) { AmqpConsole.Color = new Color(1f, 0.5f, 0); AmqpClient.Log("ERROR: " + ex.Message); AmqpConsole.Color = null; } } }
void ThrowBall() { if (!ballThrown) { if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) { ball.GetComponent <Rigidbody>().isKinematic = false; ball.GetComponent <Rigidbody>().velocity = Camera.main.transform.forward * 5; ballThrown = true; var mapScript = mapController.GetComponent <MapController>(); int tileX = mapScript.tileX; int tileY = mapScript.tileY; bool readyToSend = mapScript.okToSentPetPos; if (readyToSend) { UpdateBallState updateBall = new UpdateBallState(); updateBall.type = "updateBall"; updateBall.username = PlayerPrefs.GetString("username"); updateBall.tileX = tileX; updateBall.tileY = tileY; updateBall.ballPosX = Camera.main.transform.forward.x; updateBall.ballPosY = Camera.main.transform.forward.y; updateBall.ballPosZ = Camera.main.transform.forward.z; updateBall.ballState = "throw"; string requestJson = JsonUtility.ToJson(updateBall); AmqpClient.Publish(AmqpController.amqpControl.requestExchangeName, AmqpController.amqpControl.requestRoutingKey, requestJson); } } } } }
// Handles a disconnection event void HandleDisconnected(AmqpClient client) { Connection.interactable = true; ConnectButton.interactable = true; DisconnectButton.interactable = false; ExchangeName.interactable = false; RoutingKey.interactable = false; SubscribeButton.interactable = false; UnsubscribeButton.interactable = false; PublishButton.interactable = false; PublishExchange.interactable = false; PublishMessage.interactable = false; PublishRoutingKey.interactable = false; DeclareQueueName.interactable = false; DeclareQueueButton.interactable = false; DeleteQueueButton.interactable = false; SubscribeQueueName.interactable = false; SubscribeQueueButton.interactable = false; UnsubscribeQueueButton.interactable = false; SendMessageQueueName.interactable = false; SendMessageQueueMessage.interactable = false; SendMessageToQueueButton.interactable = false; GetAllQueueButton.interactable = false; AcknowledgeMultipleButton.interactable = false; AcknowledgeMessageButton.interactable = false; PrefetchSize.interactable = false; PrefetchCount.interactable = false; PrefetchGlobal.interactable = false; BasicQosButton.interactable = false; }
void LoginGame() { warning.text = ""; InputField usernameField = GameObject.Find("InputField_username").GetComponent <InputField>(); InputField passwordField = GameObject.Find("InputField_password").GetComponent <InputField>(); string username = usernameField.text; string password = passwordField.text; if (username == "") { warning.text = "username cannot be empty"; } if (password == "") { warning.text = "password cannot be empty"; } Debug.Log(username + " & " + password); if (username != "" && password != "") { AmqpControllerScript.amqpControl.exchangeSubscription.Handler = ProcessLogin; LoginRequestJson request = new LoginRequestJson(); request.id = id; request.type = "login"; request.username = username; request.password = password; string requestToJson = JsonUtility.ToJson(request); AmqpClient.Publish(AmqpControllerScript.amqpControl.requestExchange, AmqpControllerScript.amqpControl.requestRoutingKey, requestToJson); } }
public void returnTitle() { AmqpController.amqpControl.exchangeSubscription.Handler = ProcessReturnTitle; ReturnTitleJson request = new ReturnTitleJson(); request.id = id; request.type = "returntitle"; request.username = PlayerPrefs.GetString("username"); request.rest = PlayerPrefs.GetInt("Sleep"); request.energy = PlayerPrefs.GetInt("Food"); request.agility = PlayerPrefs.GetInt("Walk"); request.stress = PlayerPrefs.GetInt("Fun"); request.heart = PlayerPrefs.GetInt("Health"); request.money = PlayerPrefs.GetInt("Bones"); request.xp = PlayerPrefs.GetInt("XP"); string jsonRequest = JsonUtility.ToJson(request); Debug.Log(jsonRequest); AmqpClient.Publish(AmqpController.amqpControl.requestExchangeName, AmqpController.amqpControl.requestRoutingKey, jsonRequest); }