Hosting your own Pub/Sub in the cloud with AppHarbor and Hermes

As you might read in my latest post, Hermes is one our new pet projects in Tellago for doing Pub/Sub over http. The idea is simple, but still very useful for integration scenarios in the enterprise. The fact that Hermes is all based on Http and uses one of the most famous open source initiatives for NoSQL databases like MongoDB, makes this project very appealing for the cloud as well. Many of the cloud platforms already provide MongoDB as a service that you can use in your applications hosted in the cloud.

AppHarbor is probably one of the best “PaaS” solutions for running .NET applications in the cloud. The marketing slogan for this platform is “Azure done right”, so you can take your own conclusions Smile. AppHabor not only let us running any regular .NET application in the cloud, but also offers MongoDB as an addon that you can configure in your deployment, so it makes a good use case for running Hermes in the cloud.

The Hermes’s source code that you get from the GitHub repository uses by default NuGet for resolving all the external dependencies, which is not something currently supported in AppHarbor, so the first thing you need to do is to prepare the visual studio solution and all the projects to reference the binaries from a local folder (let’s say “libs”). The only project that you should deploy to the cloud is RestService, which represents the host for the REST services that you might want to use for publishing or subscribing messages to/from Hermes.

Hermes_Cloud

The line you need to comment out in the RestService project file for not using NuGet to resolve the external dependencies,

<Target Name="BeforeBuild">
    <Exec Condition="Exists('$(ProjectDir)packages.config')" Command="&quot;$(SolutionDir)..\Tools\nuget.exe&quot; install &quot;$(ProjectDir)packages.config&quot; -o &quot;$(SolutionDir)Packages&quot;" />
</Target>

Once you have that project running and using local references, you are ready to deploy it to the cloud. You might want to create a new project in AppHabor or use an existing one for doing this.

Every project in AppHarbor is basically mapped to a Git repository that you can use. Every time you make a push to that repository, they take care of building the solution, running the unit tests on it and publish it in a public address in their platform. The instructions for deploying the solution to their Git repository is all available in the project’s home page, and I can say it is pretty straightforward.

Hermes_Cloud1

The public URL will be available in the home page as well once you make the first deployment as you can see in the image above. You can also associate a MongoDB instance to the project through the Add-ons option.

You will have to configure two additional things in the configuration file (web.config) of the RestService, the public URL in AppHarbor and the MondoDB connection string (available through a configuration variable).

<connectionStrings>
    <add name="db.connectionString" connectionString="mongodb://appharbor:XXXXXXXX" />
  </connectionStrings>
  <appSettings>
    <add key="baseAddress" value="http://XXXXXXXXXX.apphb.com" />
    ............
  </appSettings>

And that’s all, once you have configured that in the web.config file and pushed those changes to AppHarbor, you should be able to start using Hermes in the cloud. You can try the Publisher and Subscriber sample applications in the source code for testing your deployment in the cloud.

Enjoy Smile

No Comments