<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Andrey Rankov on Medium]]></title>
        <description><![CDATA[Stories by Andrey Rankov on Medium]]></description>
        <link>https://medium.com/@andreyrankov?source=rss-d84e81960ffb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*T6Rn-aC5Wd8Tq1kV.</url>
            <title>Stories by Andrey Rankov on Medium</title>
            <link>https://medium.com/@andreyrankov?source=rss-d84e81960ffb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 02:26:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andreyrankov/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to connect Android to Apache ActiveMQ]]></title>
            <link>https://medium.com/@andreyrankov/how-to-connect-android-to-apache-activemq-9f6d03d21409?source=rss-d84e81960ffb------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f6d03d21409</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[messaging]]></category>
            <category><![CDATA[activemq]]></category>
            <category><![CDATA[mqtt]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Andrey Rankov]]></dc:creator>
            <pubDate>Sat, 20 Jan 2018 17:45:34 GMT</pubDate>
            <atom:updated>2020-09-07T12:56:47.911Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*jAxZdcJJtLasvb2nCrozkg.png" /></figure><p>Recently i got a task to communicate between Android app and Apache ActiveMQ server. <a href="http://activemq.apache.org/">ActiveMQ</a> is open source messaging server, very popular in Java EE world. If you reading this, probably you need to connect your app to some Java backend. In this article i will show, how to do it in easy steps. Let’s get started.</p><h4>ActiveMQ setup</h4><ol><li>Download the latest ActiveMQ release from the <a href="http://activemq.apache.org/download.html">official website</a>. If you using a Mac, choose Unix/Linux distribution. There is a distribution for Windows too.</li><li>Launch Terminal, go to distribution directory and start ActiveMQ: <br><strong>./bin/activemq start</strong></li></ol><p>Open in your browser <a href="http://localhost:8161/admin/">http://localhost:8161/admin/</a><br>Default login credentials are <strong><em>admin:admin</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cI5Atkqk1hTQQ-2pLLGOfQ.png" /></figure><p>If you see this ActiveMQ console page, your backend part is done. Let’s go to the client.</p><h4>Android setup</h4><blockquote>ActiveMQ supports bunch of transport protocols: OpenWire, STOMP, MQTT, AMQP, REST and WebSockets. We will use MQTT — it’s lightweight and perfectly fit for IoT and mobile devices due to minimal network bandwidth requirements.</blockquote><blockquote>MQTT protocol allows us to communicate with ActiveMQ server using <strong>topics</strong>. Clients may subscribe to some topic, or publish to it. In this case published message will arrive to the subscribers.</blockquote><blockquote>ActiveMQ also allows to transfer messages using <strong>queue</strong>. If you need to use it, choose another protocol, for example STOMP.</blockquote><p>For MQTT on the client we will use <a href="https://github.com/eclipse/paho.mqtt.android">Eclipse Paho Android Service</a>. It offers non-blocking API, allowing to get the messages asynchronously.</p><p>Add repository and dependencies to your build.gradle files:</p><pre>repositories {<br>    maven { url &quot;https://repo.eclipse.org/content/repositories/paho-snapshots/&quot; }<br>}</pre><pre>dependencies {<br>    implementation &#39;org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0&#39;<br>    implementation &#39;org.eclipse.paho:org.eclipse.paho.android.service:1.1.1&#39;<br>}</pre><p>If you’re using AndroidX, you should add this dependency too:</p><pre>implementation &quot;androidx.localbroadcastmanager:localbroadcastmanager:1.0.0&quot;</pre><p>Add MQTT service to <strong>AndroidManifest.xml </strong>(inside application tag):</p><p>&lt;service android:name=”org.eclipse.paho.android.service.MqttService”/&gt;</p><p>And grant required permissions:</p><pre>&lt;uses-permission android:name=”android.permission.WAKE_LOCK” /&gt;<br>&lt;uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” /&gt;<br>&lt;uses-permission android:name=”android.permission.INTERNET” /&gt;</pre><h4>Implementation</h4><p>Now we can connect to the ActiveMQ server. All job is done with help from MqttAndroidClient:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/914d9cf76ff10956683ca006735a77d2/href">https://medium.com/media/914d9cf76ff10956683ca006735a77d2/href</a></iframe><p>To set connection parameters (user name, password, timeout, reconnect etc.) use MqttConnectOptions.</p><p>Client ID may be any String, server URI must look like this:<br>String serverURI = “tcp://192.168.20.200:1883&quot;;</p><p>On successful connection we may subscribe to some topic:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3be361006252f6008cf17bca9f7aa60/href">https://medium.com/media/d3be361006252f6008cf17bca9f7aa60/href</a></iframe><p>Now we can see it working!</p><p>Launch your app, go to your ActiveMQ Console — Topics, choose your defined topic there, type any message and press Send. It will appear on your screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HLQSaf7fpRc4j4uwBsM4fg.png" /></figure><p>Publish to ActiveMQ is also very simple. Create new MqttMessage, set your string as a payload and publish with your MQTT client to some topic.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12b406e84886e9e70b7daafb56fe76c8/href">https://medium.com/media/12b406e84886e9e70b7daafb56fe76c8/href</a></iframe><p>Full working example can be found <a href="https://github.com/beersheba/MQTTClient">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f6d03d21409" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>