Installing AMQP for Unity

RabbitMQ has an excellent resource for plenty of cross-platform libraries that allow you to connect to the hub with ease. The library for C# does work well outside Unity but is problematic to set up. Fortunately, the good folks at Cymantic Labs have built and open sourced a version for Unity on GitHub. Let's see how to install this code in the next exercise:

  1. Download and unpack the code using git or as a ZIP file from https://github.com/CymaticLabs/Unity3D.Amqp:
git clone https://github.com/CymaticLabs/Unity3D.Amqp.git
  1. Switch to Unity from the menu, and select File | Open Project and navigate to the Unity3D.AmqpunityCymaticLabs.UnityAmqp folder where you installed the code. This will open the asset in its own project. Wait for the project to load.
  2. Open the Assets/CymanticLabs/Amqp/Scenes folder in the Project window (typically at the bottom).
  3. Double-click on the AmqpDemo scene to open it in the editor.
  4. Press the Play button at the top of the editor to run the scene. After you run the scene, you should see the following:
Setting the Amqp connection and sending a message
  1. Press the Connect button to connect to the local RabbitMQ.
  2. Next, under Subscriptions, set the exchange to chat, and the queue to chatout, and click Subscribe. This will subscribe to the queue so we can see any return message in the Unity console window.
  3. Finally, under Publish, set the exchange to chat, and the queue to chatin, and type a message such as hello. Click the Send button and you should see a response from the bot in the console window.

That sets up our working chatbot. Of course, this is just the start of what is possible and the reader is certainly encouraged to explore further, but keep in mind we will revisit this code later and make use of it in a later section of the book.

That completes this chapter, and now you can take advantage of it for further learning in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset