blob: 2bc133a96400f7837bcf2e64436c1d166c7cd6b5 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"><!-- Begin Jekyll SEO tag v2.8.0 -->
<title>.NET Applications and Artemis with AMQP | Blogs Archive</title>
<meta name="generator" content="Jekyll v3.9.3" />
<meta property="og:title" content=".NET Applications and Artemis with AMQP" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="On this blog post I will give a quick tutorial on how to write a .NET client with Artemis, using the AMQP libraries and protocol" />
<meta property="og:description" content="On this blog post I will give a quick tutorial on how to write a .NET client with Artemis, using the AMQP libraries and protocol" />
<link rel="canonical" href="http://localhost:4000/activemq/entry/using-net-libraries-with-activemq" />
<meta property="og:url" content="http://localhost:4000/activemq/entry/using-net-libraries-with-activemq" />
<meta property="og:site_name" content="Blogs Archive" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2017-02-06T15:01:46-05:00" />
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content=".NET Applications and Artemis with AMQP" />
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"BlogPosting","dateModified":"2017-02-06T15:01:46-05:00","datePublished":"2017-02-06T15:01:46-05:00","description":"On this blog post I will give a quick tutorial on how to write a .NET client with Artemis, using the AMQP libraries and protocol","headline":".NET Applications and Artemis with AMQP","mainEntityOfPage":{"@type":"WebPage","@id":"http://localhost:4000/activemq/entry/using-net-libraries-with-activemq"},"url":"http://localhost:4000/activemq/entry/using-net-libraries-with-activemq"}</script>
<!-- End Jekyll SEO tag -->
<link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="http://localhost:4000/feed.xml" title="Blogs Archive" /></head>
<body><header class="site-header" role="banner">
<div class="wrapper"><a class="site-title" rel="author" href="/">Blogs Archive</a><nav class="site-nav">
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger">
<span class="menu-icon">
<svg viewBox="0 0 18 15" width="18px" height="15px">
<path d="M18,1.484c0,0.82-0.665,1.484-1.484,1.484H1.484C0.665,2.969,0,2.304,0,1.484l0,0C0,0.665,0.665,0,1.484,0 h15.032C17.335,0,18,0.665,18,1.484L18,1.484z M18,7.516C18,8.335,17.335,9,16.516,9H1.484C0.665,9,0,8.335,0,7.516l0,0 c0-0.82,0.665-1.484,1.484-1.484h15.032C17.335,6.031,18,6.696,18,7.516L18,7.516z M18,13.516C18,14.335,17.335,15,16.516,15H1.484 C0.665,15,0,14.335,0,13.516l0,0c0-0.82,0.665-1.483,1.484-1.483h15.032C17.335,12.031,18,12.695,18,13.516L18,13.516z"/>
</svg>
</span>
</label>
<div class="trigger"><a class="page-link" href="/about/">About</a></div>
</nav></div>
</header>
<main class="page-content" aria-label="Content">
<div class="wrapper">
<article class="post h-entry" itemscope itemtype="http://schema.org/BlogPosting">
<header class="post-header">
<h1 class="post-title p-name" itemprop="name headline">.NET Applications and Artemis with AMQP</h1>
<p class="post-meta">
<time class="dt-published" datetime="2017-02-06T15:01:46-05:00" itemprop="datePublished">Feb 6, 2017
</time><span itemprop="author" itemscope itemtype="http://schema.org/Person"><span class="p-author h-card" itemprop="name">{"display_name"=>"Cleber suconic", "login"=>"clebertsuconic", "email"=>"clebertsuconic@apache.org"}</span></span></p>
</header>
<div class="post-content e-content" itemprop="articleBody">
<p>My first draft for this blog had a very extensive introduction about AMQP, its benefits, how business manager X would preserve its investment and blablablablaba...
<p>Lets say I cut all that #@!# and I'm jumping right to the good stuff:</p>
<p><b>AMQP is cool</b>, full of Libraries that you can bring to use with <b>ActiveMQ Artemis</b>.</p></p>
<p>One of the Libraries you can use is the <a href="https://github.com/Azure/amqpnetlite/">AMQPLite with .NET</a></p>
<p>If you just want to read the code, i have recently added the <a href="https://github.com/apache/activemq-artemis/tree/master/examples/protocols/amqp/dotnet">.NET Example on Artemis</a>, which is pretty much what I'm describing here</p>
<p>Let me give you a cooking recipe on how to write a .NET application and Apache ActiveMQ Artemis</p>
<p>Let's do it!</p>
<p><b>Step 1</b> - Install .NET</p>
<p>There is this fun video explaining how to do it. My teenager daughter would definitely be able to follow this:<br />
<br/><a href="https://channel9.msdn.com/Blogs/dotnet/Get-started-with-VS-Code-using-CSharp-and-NET-Core">https://channel9.msdn.com/Blogs/dotnet/Get-started-with-VS-Code-using-CSharp-and-NET-Core</a></p>
<p>There is also a video showing how to do it on <a href="https://channel9.msdn.com/Blogs/dotnet/Get-started-with-VS-Code-using-CSharp-and-NET-Core-on-MacOS">Mac</a> and <a href="https://channel9.msdn.com/Blogs/dotnet/Get-started-with-VS-Code-Csharp-dotnet-Core-Ubuntu">Linux</a></p>
<p><b>Step 2</b> - Write the code</p>
<p>I basically followed the steps here on this hello world app:<br />
<br/><a href="https://github.com/Azure/amqpnetlite/blob/master/docs/articles/hello_amqp.md">https://github.com/Azure/amqpnetlite/blob/master/docs/articles/hello_amqp.md</a></p>
<p>The main pitfall I had since I was very rusty on .NET was to install the AMQP.net library accordingly:</p>
<p>But I reckon it was my fault, although I could fix it in 10 min by adding this to the project.json:</p>
<pre>
"dependencies": {"AMQPNetLite": "1.2.2"},
</pre>
<p>Here is the code I have:</p>
<pre>
using System;
using Amqp;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
string address = "amqp://a:a@localhost:5672";
Connection connection = new Connection(new Address(address));
Session session = new Session(connection);
SenderLink sender = new SenderLink(session, "test-sender", "q1");
Message message1 = new Message("Hello AMQP!");
sender.Send(message1);
Console.WriteLine("Message sent into queue q1");
}
}
}
</pre>
<p><b>Step 3</b> - Create an Artemis Broker and run it</p>
<p>./artemis create /tmp/myBroker</p>
<pre>
./artemis create /tmp/mybroker
Creating ActiveMQ Artemis instance at: /private/tmp/mybroker
--user: is a mandatory property!
Please provide the default username:
a
--password: is mandatory with this configuration:
Please provide the default password:
--role: is a mandatory property!
Please provide the default role:
a
--allow-anonymous | --require-login: is a mandatory property!
Allow anonymous access? (Y/N):
y
Auto tuning journal ...
done! Your system can make 25 writes per millisecond, your journal-buffer-timeout will be 40000
You can now start the broker by executing:
"/private/tmp/mybroker/bin/artemis" run
Or you can run the broker in the background using:
"/private/tmp/mybroker/bin/artemis-service" start
</pre>
<p><p><b>Finally:</b> run the thing:</p>
<p># this will install dependencies<br/>dotnet restore</p>
<pre>
log : Restoring packages for /work/apache/six/artemis-distribution/target/apache-artemis-2.0.0-SNAPSHOT-bin/apache-artemis-2.0.0-SNAPSHOT/examples/dotnet/amqp/queue/project.json...
log : Writing lock file to disk. Path: /work/apache/six/artemis-distribution/target/apache-artemis-2.0.0-SNAPSHOT-bin/apache-artemis-2.0.0-SNAPSHOT/examples/dotnet/amqp/queue/project.lock.json
log : /work/apache/six/artemis-distribution/target/apache-artemis-2.0.0-SNAPSHOT-bin/apache-artemis-2.0.0-SNAPSHOT/examples/dotnet/amqp/queue/project.json
log : Restore completed in 741ms.
</pre>
<p># this will run the code<br/>dotnet run</p>
<pre>
Project dotnet (.NETCoreApp,Version=v1.1) will be compiled because expected outputs are missing
Compiling dotnet for .NETCoreApp,Version=v1.1
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:00.9060278
Message sent into queue q1
</pre>
<p>All of this can be done with both Artemis and ActiveMQ Classic </p>
<p>AMQP is a quite powerful and you can reuse your client libraries any way you want.</p>
</div><a class="u-url" href="/activemq/entry/using-net-libraries-with-activemq" hidden></a>
</article>
</div>
</main><footer class="site-footer h-card">
<data class="u-url" href="/"></data>
<div class="wrapper">
<h2 class="footer-heading">Blogs Archive</h2>
<div class="footer-col-wrapper">
<div class="footer-col footer-col-1">
<ul class="contact-list">
<li class="p-name">Blogs Archive</li><li><a class="u-email" href="mailto:issues@infra.apache.org">issues@infra.apache.org</a></li></ul>
</div>
<div class="footer-col footer-col-2"><ul class="social-media-list"><li><a href="https://github.com/jekyll"><svg class="svg-icon"><use xlink:href="/assets/minima-social-icons.svg#github"></use></svg> <span class="username">jekyll</span></a></li><li><a href="https://www.twitter.com/jekyllrb"><svg class="svg-icon"><use xlink:href="/assets/minima-social-icons.svg#twitter"></use></svg> <span class="username">jekyllrb</span></a></li></ul>
</div>
<div class="footer-col footer-col-3">
<p>This is an archive of the Roller blogs that were previously hosted on blogs.apache.org</p>
</div>
</div>
</div>
</footer>
</body>
</html>