<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Simon Dixon&#039;s Blog</title>
	<atom:link href="http://simonwdixon.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://simonwdixon.wordpress.com</link>
	<description>Dixon&#039;s tech ramblings</description>
	<lastBuildDate>Mon, 20 Feb 2012 19:45:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='simonwdixon.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Simon Dixon&#039;s Blog</title>
		<link>http://simonwdixon.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://simonwdixon.wordpress.com/osd.xml" title="Simon Dixon&#039;s Blog" />
	<atom:link rel='hub' href='http://simonwdixon.wordpress.com/?pushpress=hub'/>
		<item>
		<title>I&#8217;ve been a little quiet</title>
		<link>http://simonwdixon.wordpress.com/2012/01/16/ive-been-a-little-quiet/</link>
		<comments>http://simonwdixon.wordpress.com/2012/01/16/ive-been-a-little-quiet/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 21:29:50 +0000</pubDate>
		<dc:creator>simonwdixon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://simonwdixon.wordpress.com/?p=393</guid>
		<description><![CDATA[I&#8217;ve been a little quiet of late due to me starting a new job as Head of Platform Development at Brighter Option. We build advanced management tools for Facebook advertising campaigns so I&#8217;ve very busy writing  lots of c# code to talk to the Facebook Graph API.  I&#8217;ll be writing about what I&#8217;ve learnt  during [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=393&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been a little quiet of late due to me starting a new job as Head of Platform Development at <a href="http://www.brighteroption.com">Brighter Option</a>. We build advanced management tools for <a href="http://www.facebook.com">Facebook </a>advertising campaigns so I&#8217;ve very busy writing  lots of c# code to talk to the <a href="https://developers.facebook.com/docs/reference/api/">Facebook Graph API</a>.  I&#8217;ll be writing about what I&#8217;ve learnt  during the process in some upcoming posts, I&#8217;ll also be expanding on my <a title="Getting Started with RabbitMQ on Android – Part 1" href="http://simonwdixon.wordpress.com/2011/06/03/getting-started-with-rabbitmq-on-android-part-1/">RabbitMQ on Android</a> series. Stay tuned!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simonwdixon.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simonwdixon.wordpress.com/393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simonwdixon.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simonwdixon.wordpress.com/393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simonwdixon.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simonwdixon.wordpress.com/393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simonwdixon.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simonwdixon.wordpress.com/393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simonwdixon.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simonwdixon.wordpress.com/393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simonwdixon.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simonwdixon.wordpress.com/393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simonwdixon.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simonwdixon.wordpress.com/393/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=393&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simonwdixon.wordpress.com/2012/01/16/ive-been-a-little-quiet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/160f455cb11b940c8469a69b23c94b31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonwdixon</media:title>
		</media:content>
	</item>
		<item>
		<title>Shhmooze for Android released</title>
		<link>http://simonwdixon.wordpress.com/2011/09/19/shhmooze-for-android-released/</link>
		<comments>http://simonwdixon.wordpress.com/2011/09/19/shhmooze-for-android-released/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 21:35:26 +0000</pubDate>
		<dc:creator>simonwdixon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://simonwdixon.wordpress.com/?p=386</guid>
		<description><![CDATA[My latest Android app that I wrote for Shhmmoze has just been released, whoop whoop! Read more about the release here: http://blog.shhmooze.com/2011/09/19/show-some-android-love-at-your-next-conference-or-meetup/ And download the app here: https://market.android.com/details?id=com.shhmooze.UI &#160;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=386&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My latest Android app that I wrote for <a href="http://shhmooze.com/">Shhmmoze </a>has just been released, whoop whoop! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Read more about the release here:<br />
<a href="http://blog.shhmooze.com/2011/09/19/show-some-android-love-at-your-next-conference-or-meetup/">http://blog.shhmooze.com/2011/09/19/show-some-android-love-at-your-next-conference-or-meetup/</a></p>
<p>And download the app here:<br />
<a href="https://market.android.com/details?id=com.shhmooze.UI">https://market.android.com/details?id=com.shhmooze.UI</a></p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simonwdixon.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simonwdixon.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simonwdixon.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simonwdixon.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simonwdixon.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simonwdixon.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simonwdixon.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simonwdixon.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simonwdixon.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simonwdixon.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simonwdixon.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simonwdixon.wordpress.com/386/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simonwdixon.wordpress.com/386/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simonwdixon.wordpress.com/386/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=386&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simonwdixon.wordpress.com/2011/09/19/shhmooze-for-android-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/160f455cb11b940c8469a69b23c94b31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonwdixon</media:title>
		</media:content>
	</item>
		<item>
		<title>Tea Dragons Posters</title>
		<link>http://simonwdixon.wordpress.com/2011/08/19/tea-dragons-posters/</link>
		<comments>http://simonwdixon.wordpress.com/2011/08/19/tea-dragons-posters/#comments</comments>
		<pubDate>Fri, 19 Aug 2011 11:56:47 +0000</pubDate>
		<dc:creator>simonwdixon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://simonwdixon.wordpress.com/?p=378</guid>
		<description><![CDATA[Here&#8217;s a couple of posters I made for Hannah&#8217;s Tea Dragons tea stall at the Big Chill festival. One of them &#8211; Elixir of Desire &#8211; introduces a new (a vintage french nude) lady into the Tea Dragons tribe. These colours aren&#8217;t quite correct as they were produced for print in CMYK but I still think [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=378&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a couple of posters I made for Hannah&#8217;s <a href="http://www.teadragons.com">Tea Dragons</a> tea stall at the <a href="http://www.bigchill.net/festival">Big Chill</a> festival. One of them &#8211; Elixir of Desire &#8211; introduces a new (a vintage french nude) lady into the Tea Dragons tribe. These colours aren&#8217;t quite correct as they were produced for print in CMYK but I still think they look pretty cool!</p>
<p><a href="http://simonwdixon.files.wordpress.com/2011/08/elixir-of-love-big-chill.jpg"><img class="alignnone size-full wp-image-380" title="elixir-of-love-big-chill" src="http://simonwdixon.files.wordpress.com/2011/08/elixir-of-love-big-chill.jpg?w=594&#038;h=833" alt="Elixir of Love Poster" width="594" height="833" /></a></p>
<p><a href="http://simonwdixon.files.wordpress.com/2011/08/elixir-desire-big-chill.jpg"><img class="alignnone size-full wp-image-381" title="elixir-desire-big-chill" src="http://simonwdixon.files.wordpress.com/2011/08/elixir-desire-big-chill.jpg?w=594&#038;h=833" alt="Elixir of Desire Poster" width="594" height="833" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simonwdixon.wordpress.com/378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simonwdixon.wordpress.com/378/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simonwdixon.wordpress.com/378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simonwdixon.wordpress.com/378/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simonwdixon.wordpress.com/378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simonwdixon.wordpress.com/378/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simonwdixon.wordpress.com/378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simonwdixon.wordpress.com/378/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simonwdixon.wordpress.com/378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simonwdixon.wordpress.com/378/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simonwdixon.wordpress.com/378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simonwdixon.wordpress.com/378/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simonwdixon.wordpress.com/378/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simonwdixon.wordpress.com/378/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=378&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simonwdixon.wordpress.com/2011/08/19/tea-dragons-posters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/160f455cb11b940c8469a69b23c94b31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonwdixon</media:title>
		</media:content>

		<media:content url="http://simonwdixon.files.wordpress.com/2011/08/elixir-of-love-big-chill.jpg" medium="image">
			<media:title type="html">elixir-of-love-big-chill</media:title>
		</media:content>

		<media:content url="http://simonwdixon.files.wordpress.com/2011/08/elixir-desire-big-chill.jpg" medium="image">
			<media:title type="html">elixir-desire-big-chill</media:title>
		</media:content>
	</item>
		<item>
		<title>Eclipse &#8211;  Could not find App.apk!</title>
		<link>http://simonwdixon.wordpress.com/2011/08/19/eclipse-could-not-find-app-apk/</link>
		<comments>http://simonwdixon.wordpress.com/2011/08/19/eclipse-could-not-find-app-apk/#comments</comments>
		<pubDate>Fri, 19 Aug 2011 09:16:23 +0000</pubDate>
		<dc:creator>simonwdixon</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://simonwdixon.wordpress.com/?p=371</guid>
		<description><![CDATA[I started running into trouble with Eclipse this morning when I was trying to build and install an app onto my phone. The project seemed to build Ok and I got no obvious errors in the console during packing  but when  ADB tried to push the .apk to the phone I kept getting this error [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=371&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I started running into trouble with Eclipse this morning when I was trying to build and install an app onto my phone. The project seemed to build Ok and I got no obvious errors in the console during packing  but when  ADB tried to push the .apk to the phone I kept getting this error in the console</p>
<p><pre class="brush: xml;">
[2011-08-19 10:06:06 - App] Android Launch!
[2011-08-19 10:06:06 - App] adb is running normally.
[2011-08-19 10:06:06 - App] Could not find App.apk!
</pre></p>
<p>After a few hours of banging my head against the wall I remembered that before I powered down my laptop the previous day I&#8217;d updated the Android SDK using the SDK and AVD Manager.  After a little investigation it turns out the version of Eclipse I&#8217;m using(Ganymede &#8211; 3.4) is <a href="http://developer.android.com/sdk/requirements.html">not compatible</a> with the latest version of the SDK(r12.) The quick solution: update my <a title="Android SQLite Tip 2 – Use compiled SQL statements" href="http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/indigor">Eclipse install</a>, problem solved.</p>
<p>I wish I&#8217;d done this sooner, the Latest Eclipse version(Indigo) is very nice indeed!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simonwdixon.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simonwdixon.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simonwdixon.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simonwdixon.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simonwdixon.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simonwdixon.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simonwdixon.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simonwdixon.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simonwdixon.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simonwdixon.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simonwdixon.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simonwdixon.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simonwdixon.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simonwdixon.wordpress.com/371/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=371&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simonwdixon.wordpress.com/2011/08/19/eclipse-could-not-find-app-apk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/160f455cb11b940c8469a69b23c94b31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonwdixon</media:title>
		</media:content>
	</item>
		<item>
		<title>Android SQLite Tip 2 &#8211; Use compiled SQL statements</title>
		<link>http://simonwdixon.wordpress.com/2011/08/16/android-sqllite-tip-2-use-compiled-sql-statements/</link>
		<comments>http://simonwdixon.wordpress.com/2011/08/16/android-sqllite-tip-2-use-compiled-sql-statements/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 09:52:46 +0000</pubDate>
		<dc:creator>simonwdixon</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[SQLLite]]></category>

		<guid isPermaLink="false">http://simonwdixon.wordpress.com/?p=354</guid>
		<description><![CDATA[In my last article  I talked about SQL Lite inserts on Android being optimised using a transaction. Another method I&#8217;ve found that speeds things up dramatically is to use compiled SQL statements with the SQLiteStatement class. I can&#8217;t believe I hadn&#8217;t used these before, I actually think working with a compiled statement is much nicer than working with the  standard SQL [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=354&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my last <a title="Android SQLLite tip 1 – Wrap batches of writes in a transaction" href="http://simonwdixon.wordpress.com/2011/08/16/android-sqllite-tip-1-wrap-batches-of-writes-in-a-transaction/">article </a> I talked about SQL Lite inserts on Android being optimised using a transaction. Another method I&#8217;ve found that speeds things up dramatically is to use compiled SQL statements with the <a href="http://developer.android.com/reference/android/database/sqlite/SQLiteStatement.html">SQLiteStatement</a> class.</p>
<p>I can&#8217;t believe I hadn&#8217;t used these before, I actually think working with a compiled statement is much nicer than working with the  standard SQL insert/update methods but there are a couple of points to remember.</p>
<ul>
<li>They only work for INSERTS, UPDATES, DELETES or single long or string SELECTS.</li>
<li>They are not syncronized, so if using multiple threads you must roll your own syncronization.</li>
</ul>
<div>A SQLLiteStatement INSERT definition looks like this:</div>
<div><pre class="brush: java;">
SQLiteDatabase db = DBHelper.getWritableDatabase();
mInsertAttributeStatement = db.compileStatement(&quot;INSERT INTO UserProfileAttributes (UserId, AttributeKey, AttributeValue) VALUES (?,?,?)&quot;);
</pre></p>
</div>
<div>Here we are compiling the INSERT statement, we are adding parameter value place holders using the &#8216;?&#8217; keyword as you would with an <a href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#execSQL(java.lang.String)">execSql() </a>call <a href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#rawQuery(java.lang.String, java.lang.String[])">rawQuery()</a> call. The <strong>mInsertAttributeStatement  </strong>can then be reused with different parameter values as follows:</div>
<div><pre class="brush: java;">
mInsertAttributeStatement.bindLong(1, userId);
mInsertAttributeStatement.bindString(2, key);
mInsertAttributeStatement.bindString(3, value);
mInsertAttributeStatement.execute();
</pre></p>
</div>
<div>Here we are using a 1 indexed bindings to assign values to the &#8216;?&#8217; placeholders in the compiled SQL statement, nice ey!?</div>
<div>If a binding already exists at the assigned index then it will be overwritten. Bindings can be cleared at anytime using the <a href="http://developer.android.com/reference/android/database/sqlite/SQLiteProgram.html#clearBindings()">clearBindings()</a> method.</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simonwdixon.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simonwdixon.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simonwdixon.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simonwdixon.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simonwdixon.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simonwdixon.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simonwdixon.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simonwdixon.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simonwdixon.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simonwdixon.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simonwdixon.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simonwdixon.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simonwdixon.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simonwdixon.wordpress.com/354/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=354&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simonwdixon.wordpress.com/2011/08/16/android-sqllite-tip-2-use-compiled-sql-statements/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/160f455cb11b940c8469a69b23c94b31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonwdixon</media:title>
		</media:content>
	</item>
		<item>
		<title>Android SQLite tip 1 &#8211; Wrap batches of writes in a transaction</title>
		<link>http://simonwdixon.wordpress.com/2011/08/16/android-sqllite-tip-1-wrap-batches-of-writes-in-a-transaction/</link>
		<comments>http://simonwdixon.wordpress.com/2011/08/16/android-sqllite-tip-1-wrap-batches-of-writes-in-a-transaction/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 09:28:53 +0000</pubDate>
		<dc:creator>simonwdixon</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[SQLLite]]></category>

		<guid isPermaLink="false">http://simonwdixon.wordpress.com/?p=345</guid>
		<description><![CDATA[I&#8217;ve been working on the Shhmooze Android app. When the app is first run there are quite large amounts of data that need to be downloaded and persisted to an Android SQLLite db on the device(around 200o records). I was running into an issue where these writes to the db were taking a very long [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=345&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on the <a href="http://www.shhmooze.com">Shhmooze </a>Android app. When the app is first run there are quite large amounts of data that need to be downloaded and persisted to an Android SQLLite db on the device(around 200o records). I was running into an issue where these writes to the db were taking a very long time. After running a <a href="http://developer.android.com/guide/developing/debugging/debugging-tracing.html">trace </a>using the  <a href="http://developer.android.com/reference/android/os/Debug.html">Debug</a> class I discovered that the main issues were the compilation of the SQL statements and the individual writes to the db each row was taking about 15-30ms to write , this was not good.</p>
<p>I experimented and found a couple of small tweaks that make a huge difference, this first is wrapping the batch of writes in a <a href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#beginTransaction()">transaction</a>. The code looks like this:</p>
<p><pre class="brush: java;">
	        db.beginTransaction();
		for (IRemoteUser user : users) {
			saveUser(user);
		}
		db.setTransactionSuccessful();
		db.endTransaction();
</pre></p>
<p>As you can see this is pretty simple, start a transaction, write the objects to the db(in this case I&#8217;m doing this in a child method) and then commit the transaction.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simonwdixon.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simonwdixon.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simonwdixon.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simonwdixon.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simonwdixon.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simonwdixon.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simonwdixon.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simonwdixon.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simonwdixon.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simonwdixon.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simonwdixon.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simonwdixon.wordpress.com/345/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simonwdixon.wordpress.com/345/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simonwdixon.wordpress.com/345/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=345&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simonwdixon.wordpress.com/2011/08/16/android-sqllite-tip-1-wrap-batches-of-writes-in-a-transaction/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/160f455cb11b940c8469a69b23c94b31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonwdixon</media:title>
		</media:content>
	</item>
		<item>
		<title>Tea Dragons Bottle Labels</title>
		<link>http://simonwdixon.wordpress.com/2011/07/14/tea-dragons-bottle-labels/</link>
		<comments>http://simonwdixon.wordpress.com/2011/07/14/tea-dragons-bottle-labels/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 11:28:06 +0000</pubDate>
		<dc:creator>simonwdixon</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[Tea Dragons]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://simonwdixon.wordpress.com/?p=330</guid>
		<description><![CDATA[I&#8217;ve just finalised and sent to print the first bottle label for our new Tea Dragons Herbal Infusions drinks range so I thought I&#8217;d share it. The  (very tasty)drink is called Elixir of Love and  the flavour is based on Rose and Hibiscus. We are going for an old-school look with a modern twist. So first step [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=330&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just finalised and sent to print the first bottle label for our new <a href="http://www.teadragons.com/" target="_blank">Tea Dragons</a> Herbal Infusions drinks range so I thought I&#8217;d share it.</p>
<p>The  (very tasty)drink is called Elixir of Love and  the flavour is based on Rose and Hibiscus. We are going for an old-school look with a modern twist.</p>
<p>So first step was to find a model for the label, we wanted a classic looking girl, preferably an actual old photo.  After lots of trawling we found this lovely 1800&#8242;s photo of a perfect lady from <a href="http://www.graphicsfairy.blogspot.com/">Graphics Fairy</a>.  As a side note, I discovered while doing this that pretty much any picture/painting/photo produced before the 1920&#8242;s is fair game to do whatever you want with(with a few caveats.)</p>
<p><img class="alignnone size-full wp-image-340" title="lady-small" src="http://simonwdixon.files.wordpress.com/2011/07/lady-small.jpg?w=594" alt=""   /></p>
<p>As we had a rose drink, we wanted some roses on the label so again we went trawling for vintage rose pictures. There are a surprising number of websites giving away free scanned old-school images but most of ours came from the <a href="http://www.graphicsfairy.blogspot.com/">Graphics Fairy</a>. I used the roses and photos to create this concept poster.</p>
<p><a href="http://simonwdixon.files.wordpress.com/2011/07/elixir-damour-flattened.jpg"><img class="alignnone size-full wp-image-336" title="elixir-damour-flattened" src="http://simonwdixon.files.wordpress.com/2011/07/elixir-damour-flattened.jpg?w=594" alt="Elixir of Love Concept"   /></a></p>
<p>And then with a little tweaking and re-creating in illustrator I produced this final bottle label.</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simonwdixon.wordpress.com/330/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simonwdixon.wordpress.com/330/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simonwdixon.wordpress.com/330/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simonwdixon.wordpress.com/330/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simonwdixon.wordpress.com/330/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simonwdixon.wordpress.com/330/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simonwdixon.wordpress.com/330/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simonwdixon.wordpress.com/330/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simonwdixon.wordpress.com/330/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simonwdixon.wordpress.com/330/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simonwdixon.wordpress.com/330/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simonwdixon.wordpress.com/330/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simonwdixon.wordpress.com/330/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simonwdixon.wordpress.com/330/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=330&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simonwdixon.wordpress.com/2011/07/14/tea-dragons-bottle-labels/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/160f455cb11b940c8469a69b23c94b31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonwdixon</media:title>
		</media:content>

		<media:content url="http://simonwdixon.files.wordpress.com/2011/07/lady-small.jpg" medium="image">
			<media:title type="html">lady-small</media:title>
		</media:content>

		<media:content url="http://simonwdixon.files.wordpress.com/2011/07/elixir-damour-flattened.jpg" medium="image">
			<media:title type="html">elixir-damour-flattened</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting Started with RabbitMQ on Android &#8211; Part 1</title>
		<link>http://simonwdixon.wordpress.com/2011/06/03/getting-started-with-rabbitmq-on-android-part-1/</link>
		<comments>http://simonwdixon.wordpress.com/2011/06/03/getting-started-with-rabbitmq-on-android-part-1/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 23:46:29 +0000</pubDate>
		<dc:creator>simonwdixon</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[RabbitMQ]]></category>

		<guid isPermaLink="false">http://simonwdixon.wordpress.com/?p=287</guid>
		<description><![CDATA[I&#8217;ve been writing a series of posts about how to use RabbitMQ with .net. I initially started using RabbitMQ so I could push live price feeds to my white-label Android trading app VisualSpreads.  So I thought  it was now time to write an article about how to use RabbitMQ with Android. As Android is Java you can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=287&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been <a title="Getting Started With RabbitMQ in .net" href="http://simonwdixon.wordpress.com/2011/05/08/getting-started-with-rabbitmq-in-dotnet/">writing</a> a <a title="Getting Started With RabbitMQ in .net – Part 2" href="http://simonwdixon.wordpress.com/2011/05/10/getting-started-with-rabbitmq-in-net-part-2/">series</a> of <a title="Getting Started With RabbitMQ in .net – Part 3" href="http://simonwdixon.wordpress.com/2011/05/19/getting-started-with-rabbitmq-in-net-%e2%80%93-part-3/">posts</a> about how to use RabbitMQ with .net. I initially started using RabbitMQ so I could push live price feeds to my white-label Android trading app <a title="VisualSpreads" href="http://www.atplatforms.com/Solutions/VisualSpreads">VisualSpreads</a>.  So I thought  it was now time to write an article about how to use RabbitMQ with Android. As Android is Java you can follow the Java <a href="http://www.rabbitmq.com/getstarted.html">getting started</a> tutorials on the RabbitMQ website to learn the key concepts. What I will be concentrating on is the concepts and patterns related to RabbitMQ that are Android specific . I&#8217;m assuming you&#8217;ve downloaded the <a href="http://developer.android.com/sdk/index.html">Android SDK</a> and setup your <a href="http://developer.android.com/sdk/installing.html">environment </a>in eclipse. [Source Code Coming Soon]</p>
<h2>1.) Publish/Subscribe</h2>
<p>My first example is Publish/Subscribe. What I&#8217;m going to do is use and existing Publisher(Producer) from my <a title="Getting Started With RabbitMQ in .net – Part 3" href="http://simonwdixon.wordpress.com/2011/05/19/getting-started-with-rabbitmq-in-net-%e2%80%93-part-3/">last .net article </a> and write a Subscriber(Consumer) on Android. If you are not a .net person then you can use the Publisher from<a href="http://www.rabbitmq.com/tutorials/tutorial-three-java.html"> the example</a> on the RabbitMQ website.</p>
<p>Ok so first we need to create and Android project. Open up eclipse and go File -&gt; New -&gt; Android Project</p>
<p><a href="http://simonwdixon.files.wordpress.com/2011/06/new-project.png"><img class="alignnone size-full wp-image-307" title="new-project" src="http://simonwdixon.files.wordpress.com/2011/06/new-project.png?w=594" alt=""   /></a>#</p>
<p>Use the settings/names I have here. Give the package name something unique to you though <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  We won&#8217;t create a test project right now so hit &#8220;Finish&#8221;</p>
<p>Next we want to write our message consumer. We&#8217;re going to follow a similar pattern to my <a title="Getting Started With RabbitMQ in .net – Part 3" href="http://simonwdixon.wordpress.com/2011/05/19/getting-started-with-rabbitmq-in-net-%e2%80%93-part-3/">.net example</a> and crate a base class that consumers and producers can inherit from.</p>
<p>First of all we need to include the RabbitMQ Java Client Library. If you don&#8217;t have it already get the latest version <a href="http://www.rabbitmq.com/java-client.html">from here </a>.  Unzip this and find the following three files:</p>
<ul>
<li><strong>rabbitmq-client.jar</strong></li>
<li><strong>commons-io-1.2.jar</strong></li>
<li><strong>commons-io-1.2</strong></li>
</ul>
<p>Create a folder in the root of your Android project called <strong>lib</strong> , copy and paste the jars in to the new folder. The RabbitMQ client usage should be obvious but you may wonder what the other two files are used for. The RabbitMQ client uses Java API’s not included in the Android SDK Java API. These two files add the missing API’s for the RabbitMQ client to use. If you didn’t add these files you wouldn’t notice anything until runtime  when the connection to the broker would silently fail . If you then looked through the debug logcat output you would see something like this:</p>
<p><strong>WARN/System.err(9557): Caused by: java.lang.NoClassDefFoundError: com.rabbitmq.client.impl.TruncatedInputStream </strong></p>
<p>Now we need to reference the jar files in the project, go Project -&gt; Properties -&gt; Java Build Path. Click the “Add Jar” button and navigate to the <strong>lib</strong> folder and select the three jar files and click ok.</p>
<p><a href="http://simonwdixon.files.wordpress.com/2011/06/java-build-path.png"><img class="alignnone size-full wp-image-310" title="java-build-path" src="http://simonwdixon.files.wordpress.com/2011/06/java-build-path.png?w=594&#038;h=447" alt="" width="594" height="447" /></a></p>
<p>Ok now to the base class. Add a new class IConnectToRabbitMQ as follows</p>
<p><pre class="brush: java;">
/**
 * Base class for objects that connect to a RabbitMQ Broker
 */
public abstract class IConnectToRabbitMQ {
	  public String mServer;
      public String mExchange;

      protected Channel mModel = null;
      protected Connection  mConnection;

      protected boolean Running ;

      protected  String MyExchangeType ;

      /**
       *
       * @param server The server address
       * @param exchange The named exchange
       * @param exchangeType The exchange type name
       */
      public IConnectToRabbitMQ(String server, String exchange, String exchangeType)
      {
    	  mServer = server;
    	  mExchange = exchange;
          MyExchangeType = exchangeType;
      }

      public void Dispose()
      {
          Running = false;

			try {
				if (mConnection!=null)
					mConnection.close();
				if (mModel != null)
					mModel.abort();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

      }

      /**
       * Connect to the broker and create the exchange
       * @return success
       */
      public boolean connectToRabbitMQ()
      {
    	  if(mModel!= null &amp;&amp; mModel.isOpen() )//already declared
    		  return true;
          try
          {
        	  ConnectionFactory connectionFactory = new ConnectionFactory();
              connectionFactory.setHost(mServer);
              mConnection = connectionFactory.newConnection();
              mModel = mConnection.createChannel();
              mModel.exchangeDeclare(mExchange, MyExchangeType, true);

              return true;
          }
          catch (Exception e)
          {
        	  e.printStackTrace();
              return false;
          }
      }
}
</pre></p>
<p>You should be able to see the similarities here to the .net example. What I’ve tried to do is keep the Android and .net code as similar as possible as I switch between the two quite often.  Here is a summary of the main differences</p>
<p><strong>The use of a concrete Chanel and Connection</strong></p>
<p><pre class="brush: java;">

//Java

protected Channel mModel = null;

protected Connection  mConnection;

</pre></p>
<p>Instead of a IModel and IConnection</p>
<p><pre class="brush: java;">

//.net

protected IModel Model { get; set; }

protected IConnection Connection { get; set; }

</pre></p>
<p>The Connection and Model initialisation code is also slightly different</p>
<p><pre class="brush: java;">

//Java

connectionFactory.setHost(mServer);

mConnection = connectionFactory.newConnection()

mModel = mConnection.createChannel();

</pre></p>
<p>As opposed to in .net</p>
<p><pre class="brush: java;">

//.net

connectionFactory.HostName = Server;

Connection = connectionFactory.CreateConnection();

Model = Connection.CreateModel();

</pre></p>
<p>Now we need to write our Consumer that will inherit from this base class. There are a few more differences here when compared to .net but the basic pattern is exactly the same.</p>
<p><pre class="brush: java;">
/**
 *Consumes messages from a RabbitMQ broker
 *
 */
public class MessageConsumer extends  IConnectToRabbitMQ{

	public MessageConsumer(String server, String exchange, String exchangeType) {
		super(server, exchange, exchangeType);
	}

	//The Queue name for this consumer
    private String mQueue;
    private QueueingConsumer MySubscription;

    //last message to post back
    private byte[] mLastMessage;

    // An interface to be implemented by an object that is interested in messages(listener)
    public interface OnReceiveMessageHandler{
    	public void onReceiveMessage(byte[] message);
    };

    //A reference to the listener, we can only have one at a time(for now)
    private OnReceiveMessageHandler mOnReceiveMessageHandler;

    /**
     *
     * Set the callback for received messages
     * @param handler The callback
     */
    public void setOnReceiveMessageHandler(OnReceiveMessageHandler handler){
    	mOnReceiveMessageHandler = handler;
    };

    private Handler mMessageHandler = new Handler();
    private Handler mConsumeHandler = new Handler();

    // Create runnable for posting back to main thread
    final Runnable mReturnMessage = new Runnable() {
        public void run() {
        	mOnReceiveMessageHandler.onReceiveMessage(mLastMessage);
        }
    };

    final Runnable mConsumeRunner = new Runnable() {
        public void run() {
        	Consume();
        }
    };

    /**
     * Create Exchange and then start consuming. A binding needs to be added before any messages will be delivered
     */
    @Override
    public boolean connectToRabbitMQ()
    {
       if(super.connectToRabbitMQ())
       {

           try {
        	   mQueue = mModel.queueDeclare().getQueue();
        	   MySubscription = new QueueingConsumer(mModel);
        	   mModel.basicConsume(mQueue, false, MySubscription);
			} catch (IOException e) {
				e.printStackTrace();
				return false;
			}
			 if (MyExchangeType == &quot;fanout&quot;)
	               AddBinding(&quot;&quot;);//fanout has default binding

	        Running = true;
			mConsumeHandler.post(mConsumeRunner);

           return true;
       }
       return false;
    }

    /**
     * Add a binding between this consumers Queue and the Exchange with routingKey
     * @param routingKey the binding key eg GOOG
     */
    public void AddBinding(String routingKey)
    {
        try {
			mModel.queueBind(mQueue, mExchange, routingKey);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }

    /**
     * Remove binding between this consumers Queue and the Exchange with routingKey
     * @param routingKey the binding key eg GOOG
     */
    public void RemoveBinding(String routingKey)
    {
        try {
			mModel.queueUnbind(mQueue, mExchange, routingKey);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }

    private void Consume()
    {
    	Thread thread = new Thread()
    	{

    		 @Override
    		    public void run() {
    			 while(Running){
			    	QueueingConsumer.Delivery delivery;
				    try {
				        delivery = MySubscription.nextDelivery();
			        	mLastMessage = delivery.getBody();
			        	mMessageHandler.post(mReturnMessage);
			    	    try {
							mModel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
						} catch (IOException e) {
							e.printStackTrace();
						}
				    } catch (InterruptedException ie) {
				    	ie.printStackTrace();
				    }
    			 }
    		 }
    	};
    	thread.start();

    }

    public void dispose(){
    	Running = false;
    }
}
</pre></p>
<p>Ok, lets look at the Android specific bits here.  The first code of interest is this</p>
<p><pre class="brush: java;">
    // An interface to be implemented by an object that is interested in messages(listener)
    public interface OnReceiveMessageHandler{
    	public void onReceiveMessage(byte[] message);
    };

    //A reference to the listener, we can only have one at a time(for now)
    private OnReceiveMessageHandler mOnReceiveMessageHandler;

    /**
     *
     * Set the callback for received messages
     * @param handler The callback
     */
    public void setOnReceiveMessageHandler(OnReceiveMessageHandler handler){
    	mOnReceiveMessageHandler = handler;
    };
</pre></p>
<p>What we are doing here is declaring an interface <strong>OnReceiveMessageHandler{}</strong> that a message listener will implement. We want to have one listener at a time which we keep a reference to in  <strong>mOnReceiveMessageHandler</strong>. We can set the listener by using the method <strong>setOnReceiveMessageHandler(OnReceiveMessageHandler handler)</strong> . This is a standard Android pattern and is used throughout the SDK for onClick listeners etc.</p>
<p>Next we have</p>
<p><pre class="brush: java;">
private Handler mMessageHandler = new Handler();
private Handler mConsumeHandler = new Handler();
</pre></p>
<p>Here we are declaring two <a href="http://developer.android.com/reference/android/os/Handler.html">Handler</a>. A handler is a special object in Android that is used to safely pass data between processes (Threads) and to execute Runnables. It’s vaguely like a delegate in .net</p>
<p>Next we have two R<a href="http://developer.android.com/reference/java/lang/Runnable.html">unnable</a>.</p>
<p><pre class="brush: java;">
// Create runnable for posting back to main thread
    final Runnable mReturnMessage = new Runnable() {
        public void run() {
        	mOnReceiveMessageHandler.onReceiveMessage(mLastMessage);
        }
    };

    final Runnable mConsumeRunner = new Runnable() {
        public void run() {
        	Consume();
        }
    };
</pre></p>
<p>A runnable is a block of work that can be passed to a new Thread for execution. We will be using our Handlers to run(or post) these Runnables . This is slightly confusing but a very important concept to get a grasp of if you plan to do anything but trivial Android development.</p>
<p>Now within the connectToRabbitMq()  method we have this:</p>
<p><pre class="brush: java;">&lt;/pre&gt;
mConsumeHandler.post(mConsumeRunner);

</pre></p>
<p>This is posting the  <strong>mConsumeRunner</strong> runnable to the <strong>mConsumeHandler</strong> for execution on a new Thread. <strong>mConsumeHandler</strong> will call the<strong> run()</strong> method of the <strong>mConsumeRunner</strong>. This in turn calls the <strong>Consume()</strong> method which spawns a new blocking message-listening/de-queuing thread.</p>
<p>When we have a new message we then call</p>
<p><pre class="brush: java;">
mMessageHandler.post(mReturnMessage);

</pre></p>
<p>This invokes the <strong>mReturnMessage</strong> runnable which in turn calls the <strong>mOnReceiveMessageHandler.onReceiveMessage(mLastMessage) </strong> listener/handler, phew <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>If this is looking confusing then please <a href="http://android-developers.blogspot.com/2009/05/painless-threading.html">read more</a> about <a href="http://developer.android.com/reference/java/lang/Runnable.html">Runnables</a>, <a href="http://developer.android.com/reference/java/lang/Thread.html">Threads </a>and <a href="http://developer.android.com/reference/android/os/Handler.html">Handlers</a>. It is <em>very important</em>.</p>
<p>We now have our consuming code, lets use it. We need to output the messages somewhere so we need a TextView to display it. In the project folder structure open <strong>/res/layout/</strong> there should be a file in there called <strong>main.xm</strong>l. Open this file up and make sure it looks like this:</p>
<p><pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;ScrollView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:orientation=&quot;vertical&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;wrap_content&quot;
    &gt;
&lt;TextView
	android:id=&quot;@+id/output&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:text=&quot;@string/hello&quot;
    /&gt;
&lt;/ScrollView&gt;
</pre></p>
<p>What we have here is a root <strong>ScrollView</strong> containing one <strong>TextView</strong> with an ID of output.</p>
<p>Next open up the <strong>ActivityHome.java</strong> file we created with the project. Make it look like this.</p>
<p><pre class="brush: java;">
public class ActivityHome extends Activity {
	private MessageConsumer mConsumer;
	private TextView mOutput;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //The output TextView we'll use to display messages
        mOutput =  (TextView) findViewById(R.id.output);

        //Create the consumer
        mConsumer = new MessageConsumer(&quot;192.168.1.67&quot;,
        		&quot;logs&quot;,
        		&quot;fanout&quot;);

        //Connect to broker
        mConsumer.connectToRabbitMQ();

        //register for messages
        mConsumer.setOnReceiveMessageHandler(new OnReceiveMessageHandler(){

			public void onReceiveMessage(byte[] message) {
				String text = &quot;&quot;;
				try {
					text = new String(message, &quot;UTF8&quot;);
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}

				mOutput.append(&quot;\n&quot;+text);
			}
        });

    }

    @Override
	protected void onResume() {
		super.onPause();
		mConsumer.connectToRabbitMQ();
	}

	@Override
	protected void onPause() {
		super.onPause();
		mConsumer.dispose();
	}
}
</pre></p>
<p>This should all be fairly self explanatory. We get a reference to our output view, create the and connect the consumer. <strong>When creating the consumer you must use the IP of your rabbitMQ broker machine(in may case &#8220;192.168.1.67&#8243;) on your local network not &#8220;localhost&#8221;</strong>.  We then listen for messages with a new setOnReceiveMessageHandler.</p>
<p>We are stopping the Consumer <strong>onPause</strong>. This is very good practise as it stops us draining the device battery and data allowance.</p>
<p>Now we need to test it!</p>
<p>If we ran this now it wouldn&#8217;t work. We need to tell the Android system this app is allowed to access the internet(and in turn the broker). In the root of the project open <strong>AndroidManifest.xml. </strong>Just before the closing <strong>/manifest </strong>tag, add this permission.</p>
<p><pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;com.atplatforms.rabbitmq&quot;
      android:versionCode=&quot;1&quot;
      android:versionName=&quot;1.0&quot;&gt;
     ......
    &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;&gt;&lt;/uses-permission&gt;
&lt;/manifest&gt;
</pre></p>
<p>Hit Run -&gt; Run. The app will start in the emulator or you connected Android device.</p>
<p>Then startup the .net Form app from the <a title="Getting Started With RabbitMQ in .net – Part 3" href="http://simonwdixon.wordpress.com/2011/05/19/getting-started-with-rabbitmq-in-net-%e2%80%93-part-3/">last .net example</a>.</p>
<p>Start up a consumer and send a message. You should get the same message on both the Consumer running on your desktop machine and on your Android device. Nice <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://simonwdixon.files.wordpress.com/2011/06/pc-output.png"><img class="alignnone size-full wp-image-316" title="pc-output" src="http://simonwdixon.files.wordpress.com/2011/06/pc-output.png?w=594" alt=""   /></a><img class="alignnone size-full wp-image-315" title="android-output2" src="http://simonwdixon.files.wordpress.com/2011/06/android-output22.png?w=594" alt=""   /></p>
<p>Take a moment to consider this. What we have here is very cool, we can send a message to all connected consumers without ever knowing they are there or how many there are.  We are sending messages cross language , platform and OS with very little work. We could use this exact same code to send these messages to thousands of Android hansets with no problem if we wanted to.</p>
<p>In the next example I&#8217;ll start to get a little more complex sending some more interesting messages using both .net and Android, I&#8217;ll also be looking at routing. [Code available soon]</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simonwdixon.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simonwdixon.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simonwdixon.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simonwdixon.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simonwdixon.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simonwdixon.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simonwdixon.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simonwdixon.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simonwdixon.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simonwdixon.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simonwdixon.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simonwdixon.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simonwdixon.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simonwdixon.wordpress.com/287/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=287&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simonwdixon.wordpress.com/2011/06/03/getting-started-with-rabbitmq-on-android-part-1/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/160f455cb11b940c8469a69b23c94b31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonwdixon</media:title>
		</media:content>

		<media:content url="http://simonwdixon.files.wordpress.com/2011/06/new-project.png" medium="image">
			<media:title type="html">new-project</media:title>
		</media:content>

		<media:content url="http://simonwdixon.files.wordpress.com/2011/06/java-build-path.png" medium="image">
			<media:title type="html">java-build-path</media:title>
		</media:content>

		<media:content url="http://simonwdixon.files.wordpress.com/2011/06/pc-output.png" medium="image">
			<media:title type="html">pc-output</media:title>
		</media:content>

		<media:content url="http://simonwdixon.files.wordpress.com/2011/06/android-output22.png" medium="image">
			<media:title type="html">android-output2</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting Started With RabbitMQ in .net – Part 3</title>
		<link>http://simonwdixon.wordpress.com/2011/05/19/getting-started-with-rabbitmq-in-net-%e2%80%93-part-3/</link>
		<comments>http://simonwdixon.wordpress.com/2011/05/19/getting-started-with-rabbitmq-in-net-%e2%80%93-part-3/#comments</comments>
		<pubDate>Thu, 19 May 2011 22:14:46 +0000</pubDate>
		<dc:creator>simonwdixon</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[RabbitMQ]]></category>

		<guid isPermaLink="false">http://simonwdixon.wordpress.com/?p=248</guid>
		<description><![CDATA[In the previous two examples I built a simple .net application to demonstrate first two sections the RabbitMQ getting started guide in .net. In this post I&#8217;ll be looking at the third. Download the Source 3.) Publish/Subscribe The original article (in Java) is here:http://www.rabbitmq.com/tutorials/tutorial-three-java.html I&#8217;m going to take a slightly different approach to my previous [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=248&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the <a title="Getting Started With RabbitMQ in .net" href="http://simonwdixon.wordpress.com/2011/05/08/getting-started-with-rabbitmq-in-dotnet/">previous</a> <a title="Getting Started With RabbitMQ in .net – Part 2" href="http://simonwdixon.wordpress.com/2011/05/10/getting-started-with-rabbitmq-in-net-part-2/">two</a> examples I built a simple .net application to demonstrate first two sections the RabbitMQ <a href="http://www.rabbitmq.com/getstarted.html">getting started</a> guide in .net. In this post I&#8217;ll be looking at the third. <a href="http://code.google.com/p/getting-started-with-rabbitmq/">Download the Source</a></p>
<h2>3.) Publish/Subscribe</h2>
<p>The original article (in Java) is here:<a href="http://www.rabbitmq.com/tutorials/tutorial-three-java.html">http://www.rabbitmq.com/tutorials/tutorial-three-java.html</a></p>
<p>I&#8217;m going to take a slightly different approach to my previous two examples and split the Producer and Consumer into two different Windows Forms. This will allow us to run as many Consumers as we like  and so demonstrate Pub/Sub effectively.</p>
<p>First up is the Producer.</p>
<p>Create a new Form and add the Input TextBox and Button as in the first two examples. Also and a new Button &#8220;Start New Consumer&#8221; .</p>
<p><a href="http://simonwdixon.files.wordpress.com/2011/05/pubsub-producer-form.png"><img class="alignnone size-full wp-image-262" title="PubSub-Producer-Form" src="http://simonwdixon.files.wordpress.com/2011/05/pubsub-producer-form.png?w=594&#038;h=354" alt="" width="594" height="354" /></a></p>
<p>Next create the consumer. We only need to output messages so we only need one RichTextBox</p>
<p><a href="http://simonwdixon.files.wordpress.com/2011/05/pubsub-consumer-form.png"><img class="alignnone size-full wp-image-263" title="PubSub-Consumer-Form" src="http://simonwdixon.files.wordpress.com/2011/05/pubsub-consumer-form.png?w=594" alt=""   /></a></p>
<p>In the previous two examples we had pretty much duplicate constructors for both Consumers and Producers. We will now fix this by creating a base class that these can both inherit from. Create a new class called <strong>IConnectToRabbitMQ</strong>.</p>
<p><pre class="brush: java;">
public abstract class IConnectToRabbitMQ : IDisposable
    {
        protected IModel Model { get; set; }
        protected IConnection Connection { get; set; }
        public string Server { get; set; }
        public string ExchangeName{ get; set; }
        public string ExchangeTypeName { get; set; }

        public IConnectToRabbitMQ(string server, string exchange, string exchangeType)
        {
            Server = server;
            Exchange = exchange;
            ExchangeTypeName = exchangeType;
        }
        //Create the connection, Model and Exchange(if one is required)
        public virtual bool ConnectToRabbitMQ()
        {
            try
            {
                var connectionFactory = new ConnectionFactory();
                connectionFactory.HostName = Server;
                Connection = connectionFactory.CreateConnection();
                Model = Connection.CreateModel();
                bool durable = true;
                if (!String.IsNullOrEmpty(Exchange))
                    Model.ExchangeDeclare(Exchange, ExchangeTypeName, durable);
                return true;
            }
            catch (BrokerUnreachableException e)
            {
                return false;
            }
        }

        public void Dispose()
        {
            if (Connection != null)
                Connection.Close();
            if (Model != null)
                Model.Abort();
        }
    }
</pre></p>
<p>The class name may look a little odd to most as it begins with an &#8220;I&#8221;, this is usually the naming convention for an Interface but I&#8217;m using what I like to call <em><strong>Simon Says</strong></em> naming convention. I&#8217;ll be writing a post about this in the near future. The main gist of it, is I like to have classes tell me what they do. For example, a class which calls a remote service might inherit from a class(or interface) called <strong>ICallRemoteServices</strong>. So the full class name definition would be <strong>FooService : ICallRemoteServices</strong>. There would also be a abstract method defined that implements the action e.g <strong>CallRemoteService</strong>.  Other example are  <strong>IAmAnOrder</strong>(for a value object), <strong>ICalculateShipping</strong>, <strong>IDeliverEmail</strong> etc. This may seem a little weird but I like it <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>So enough of that for now, lets go through the class. First we declare fields to hold the familiar <strong>IModel</strong> and <strong>Connection</strong> instances. Next up are fields to store the details of the <strong>Server</strong>, <strong>Exchange</strong> and <strong>ExchangeTypeName</strong>.  <strong>Exchange</strong> is the name of the exchange we want to publish/consume messages from and <strong>ExchangeTypeName </strong> holds the type of exchange we want to use(in this example it will be &#8220;fanout&#8221;).  <strong>ExchangeType </strong>is set from a constant declared in the<a href="http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v2.4.1/rabbitmq-dotnet-client-2.4.1-client-htmldoc/html/type-RabbitMQ.Client.ExchangeType.html"> </a><a href="http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v2.4.1/rabbitmq-dotnet-client-2.4.1-client-htmldoc/html/type-RabbitMQ.Client.ExchangeType.html">RabbitMQ.Client.ExchangeTyp</a><strong><a href="http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v2.4.1/rabbitmq-dotnet-client-2.4.1-client-htmldoc/html/type-RabbitMQ.Client.ExchangeType.html">e</a>  </strong>class, so for us it will be <strong>ExchangeType .Fanout</strong>(More on this later.) Next we have the  ConnectToRabbitMQ() method, this is almost exactly the same as the Constructor methods of the Producer/Consumer methods  in my  <a title="Getting Started With RabbitMQ in .net" href="http://simonwdixon.wordpress.com/2011/05/08/getting-started-with-rabbitmq-in-dotnet/">previous</a> <a title="Getting Started With RabbitMQ in .net – Part 2" href="http://simonwdixon.wordpress.com/2011/05/10/getting-started-with-rabbitmq-in-net-part-2/">two</a> examples. We have this additional block which declares the Exchange.</p>
<p><pre class="brush: plain;">
                bool durable = true;
                if (!String.IsNullOrEmpty(ExchangeName))
                    Model.ExchangeDeclare(ExchangeName, ExchangeTypeName, durable);
</pre></p>
<p>We are declaring a <strong>durable</strong> exchange of the type <strong>ExchangeTypeName </strong>with the name <strong>ExchangeName.  </strong>If this exchange had already been declared by another Producer or Consumer  a new one is not created, the existing one will be used.</p>
<p>Now we&#8217;ll write our Producer.</p>
<p><pre class="brush: java;">
public class Producer : IConnectToRabbitMQ
    {
        public Producer(string server, string exchange, string exchangeType) : base(server, exchange, exchangeType)
        {
        }

        public void SendMessage(byte[] message)
        {
            IBasicProperties basicProperties = Model.CreateBasicProperties();
            basicProperties.SetPersistent(true);
            Model.BasicPublish(ExchangeName, &quot;&quot;, basicProperties, message);
        }
    }
}
</pre></p>
<p>Here we a have a nice lightweight publisher, the only difference from our previous examples is we are publishing to a named exchange called <strong>ExchangeName. </strong>We do not know about or use a Queue.</p>
<p>Then it&#8217;s our consumer, this is slightly more complicated.</p>
<p><pre class="brush: java;">
public class Consumer : IConnectToRabbitMQ
    {
        protected bool isConsuming;
        protected string QueueName;

        // used to pass messages back to UI for processing
        public delegate void onReceiveMessage(byte[] message);
        public event onReceiveMessage onMessageReceived;

        public Consumer(string server, string exchange, string exchangeType) : base(server, exchange, exchangeType)
        {
        }

        //internal delegate to run the consuming queue on a seperate thread
        private delegate void ConsumeDelegate();

        public void StartConsuming()
        {
                Model.BasicQos(0, 1, false);
                QueueName = Model.QueueDeclare();
                Model.QueueBind(QueueName, ExchangeName, &quot;&quot;);
                isConsuming = true;
                ConsumeDelegate c = new ConsumeDelegate(Consume);
                c.BeginInvoke(null, null);
        }

        protected Subscription mSubscription { get; set; }

        private void Consume()
        {
            bool autoAck = false;

            //create a subscription
            mSubscription = new Subscription(Model, QueueName, autoAck);

            while (isConsuming)
            {
                BasicDeliverEventArgs e = mSubscription.Next();
                byte[] body = e.Body;
                onMessageReceived(body);
                mSubscription.Ack(e);

            }
        }

        public void Dispose()
        {
            isConsuming = false;
            base.Dispose();
        }
    }
</pre></p>
<p>We need to store the name of our Queue that we will be binding to the exchange so we have a field <strong>QueueName </strong>for this purpose. The next code of interest is the <strong>StartConsuming()</strong> method. Most of this is familiar with this additional block:</p>
<p><pre class="brush: java;">
 QueueName = Model.QueueDeclare();
 Model.QueueBind(QueueName, ExchangeName, &quot;&quot;);
 </pre></p>
<p>What we are doing here is asking the model to declare a temporary queue for us and give it a random unique name(stored in <strong>QueueName</strong>), we then bind this queue to the Exchange called <strong>ExchangeName. </strong></p>
<p>This a key concept to exchanges in RabbitMQ, a publisher/producer only knows about the Exchange, it will publish messages directly to the Exchange and has no concept of a queue. Each consumer knows about the Exchange but they will also have a queue that is bound to the Exchange.  The way I look at it is the one or more Producers own an Exchange(and publish to it) and each Consumer owns a Queue(which is bound to an Exchange.)</p>
<p>The Consume() method is very different to what we have seen before(and the Java Example). Instead of using a  <strong>QueueingBasicConsumer </strong>we are using a <strong>Subscription. </strong>Subscription is part of the <a href="http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v2.4.1/rabbitmq-dotnet-client-2.4.1-client-htmldoc/html/namespace-RabbitMQ.Client.MessagePatterns.html">RabbitMQ.Client.MessagePatterns</a> package in the .net client Library. It give us a nice wrapper to the boilerplate message de-queuing code. More info<a href="http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v2.4.1/rabbitmq-dotnet-client-2.4.1-client-htmldoc/html/type-RabbitMQ.Client.MessagePatterns.Subscription.html"> is here</a>.</p>
<p><pre class="brush: java;">
        mSubscription = new Subscription(Model, QueueName, autoAck);
          .....
          BasicDeliverEventArgs e = mSubscription.Next();
          .....
          mSubscription.Ack(e);
</pre></p>
<p>Now we need to add the code for our Producer Form</p>
<p><pre class="brush: java;">
       public string HOST_NAME = &quot;localhost&quot;;
        public string EXCHANGE_NAME = &quot;logs&quot;;

        private Producer producer;

        //delegate to show messages on the UI thread
        private delegate void showMessageDelegate(string message);

        public PubSub_Producer()
        {
            InitializeComponent();

            //Declare the producer
            producer = new Producer(HOST_NAME, EXCHANGE_NAME, ExchangeType.Fanout);

            //connect to RabbitMQ
            if(!producer.ConnectToRabbitMQ())
            {
                //Show a basic error if we fail
                MessageBox.Show(&quot;Could not connect to Broker&quot;);
            }

        }

        private int count = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            string message = String.Format(&quot;{0} - {1}&quot;, count++, textBox1.Text);
            producer.SendMessage(System.Text.Encoding.UTF8.GetBytes(message));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //Open a new Consumer Form
            PubSub_Consumer consumer = new PubSub_Consumer();
            consumer.Show();
        }
</pre></p>
<p>This should be fairly self explanatory. The <strong>producer.ConnectToRabbitMQ() </strong>call is handled in the base<strong> IConnectToRabbitMQ </strong>class. We&#8217;ve added little error handling code just in case the broker is unavailable(if it is run <strong>rabbitmq-server -detached </strong>from the command line .) There&#8217;s also a method to handle clicks on the &#8220;Start New Consumer&#8221; Button which spawns a new Consumer Form.</p>
<p>Then we have our Consumer Form.</p>
<p><pre class="brush: java;">
public partial class PubSub_Consumer : Form
    {
        public string HOST_NAME = &quot;localhost&quot;;
        public string EXCHANGE_NAME = &quot;logs&quot;;

        private Consumer consumer;
        public PubSub_Consumer()
        {
            InitializeComponent();
            //create the consumer
            consumer = new Consumer(HOST_NAME, EXCHANGE_NAME, ExchangeType.Fanout);

            //connect to RabbitMQ
            if (!consumer.ConnectToRabbitMQ())
            {
                //Show a basic error if we fail
                MessageBox.Show(&quot;Could not connect to Broker&quot;);
            }

            //Register for message event
            consumer.onMessageReceived += handleMessage;

            //Start consuming
            consumer.StartConsuming();
        }

        //delegate to post to UI thread
        private delegate void showMessageDelegate(string message);

        //Callback for message receive
        public void handleMessage(byte[] message)
        {
            showMessageDelegate s = new showMessageDelegate(richTextBox1.AppendText);
            this.Invoke(s, System.Text.Encoding.UTF8.GetString(message) + Environment.NewLine);
        }
    }
</pre></p>
<p>This is exactly the same as previous Consumer examples with the additional call to the base class.</p>
<p>Now we can run the project after making sure the correct Form is opened on starup</p>
<p><pre class="brush: java;">
   [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new PubSub_Producer());
        }
</pre></p>
<p>Click the &#8220;Start New Consumer&#8221; Button a couple of time to get a few consumers running, then put  your message in the &#8220;Producer Input&#8221;  TextBox and hit send. You should see the message appear in all the Consumer output windows. Good stuff <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://simonwdixon.files.wordpress.com/2011/05/pub-sub-output.png"><img class="alignnone size-full wp-image-265" title="pub-sub-output" src="http://simonwdixon.files.wordpress.com/2011/05/pub-sub-output.png?w=594" alt=""   /></a></p>
<h3>Summary</h3>
<p>What we have done here is create a <a href="http://www.rabbitmq.com/tutorials/tutorial-three-java.html">Fanout Exchange</a> named &#8220;logs&#8221;,  we&#8217;ve created some Consumers(three in my example above) each with their own unique temporary queue bound to the exchange. We have then published a message to the exchange using our Producer, the exchange then routes the message to all bound queues which in turn delivers it to the Consumers. <a href="http://code.google.com/p/getting-started-with-rabbitmq/">Download the Source</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simonwdixon.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simonwdixon.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simonwdixon.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simonwdixon.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simonwdixon.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simonwdixon.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simonwdixon.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simonwdixon.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simonwdixon.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simonwdixon.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simonwdixon.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simonwdixon.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simonwdixon.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simonwdixon.wordpress.com/248/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=248&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simonwdixon.wordpress.com/2011/05/19/getting-started-with-rabbitmq-in-net-%e2%80%93-part-3/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/160f455cb11b940c8469a69b23c94b31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonwdixon</media:title>
		</media:content>

		<media:content url="http://simonwdixon.files.wordpress.com/2011/05/pubsub-producer-form.png" medium="image">
			<media:title type="html">PubSub-Producer-Form</media:title>
		</media:content>

		<media:content url="http://simonwdixon.files.wordpress.com/2011/05/pubsub-consumer-form.png" medium="image">
			<media:title type="html">PubSub-Consumer-Form</media:title>
		</media:content>

		<media:content url="http://simonwdixon.files.wordpress.com/2011/05/pub-sub-output.png" medium="image">
			<media:title type="html">pub-sub-output</media:title>
		</media:content>
	</item>
		<item>
		<title>Somebody is reading my Blog!</title>
		<link>http://simonwdixon.wordpress.com/2011/05/13/somebody-is-reading-my-blog/</link>
		<comments>http://simonwdixon.wordpress.com/2011/05/13/somebody-is-reading-my-blog/#comments</comments>
		<pubDate>Fri, 13 May 2011 10:57:29 +0000</pubDate>
		<dc:creator>simonwdixon</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[RabbitMQ]]></category>

		<guid isPermaLink="false">http://simonwdixon.wordpress.com/?p=251</guid>
		<description><![CDATA[I&#8217;ve only really starting blogging properly recently, I&#8217;ve been meaning to do it for years but I always seemed to be too busy or didn&#8217;t know what to write about. A little a while ago I decided to make a big effort to actually write some posts/articles that were useful.  I can now be happy that is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=251&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve only really starting blogging properly recently, I&#8217;ve been meaning to do it for years but I always seemed to be too busy or didn&#8217;t know what to write about. A little a while ago I decided to make a big effort to actually write some posts/articles that were useful.  I can now be happy that is wasn&#8217;t in vain as I can now say SOMEBODY IS ACTUALLY READING MY BLOG. I just found <a href="http://stackoverflow.com/questions/5951477/publish-subscribe-samples-with-rabbitmq-in-net">this question</a> on stackoverflow where somebody has read my <a title="Getting Started With RabbitMQ in .net" href="http://simonwdixon.wordpress.com/2011/05/08/getting-started-with-rabbitmq-in-dotnet/">article about RabbitMQ</a>,  downloaded the code and built a project.  Nice <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Now  I wish I&#8217;d started sooner, it&#8217;s a good feeling!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/simonwdixon.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/simonwdixon.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/simonwdixon.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/simonwdixon.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/simonwdixon.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/simonwdixon.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/simonwdixon.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/simonwdixon.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/simonwdixon.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/simonwdixon.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/simonwdixon.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/simonwdixon.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/simonwdixon.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/simonwdixon.wordpress.com/251/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simonwdixon.wordpress.com&amp;blog=14154130&amp;post=251&amp;subd=simonwdixon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simonwdixon.wordpress.com/2011/05/13/somebody-is-reading-my-blog/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/160f455cb11b940c8469a69b23c94b31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">simonwdixon</media:title>
		</media:content>
	</item>
	</channel>
</rss>
