SlideShare a Scribd company logo
CamelOne 2013
June 10-11 2013
Boston, MA
Messaging for web and
mobile with Apache
ActiveMQ
By Bosanac Dejan
1
CamelOne 2013
CamelOne
2
Bosanac Dejan?
• Senior Sofware Engineer at RedHat
• Apache ActiveMQ committer and PMC member
• Co-author of ActiveMQ in Action
• Blog – http://sensatic.net
• Twitter – http://twitter.com/dejanb
CamelOne 2013
CamelOne
Agenda
• Challenges of web messaging
• REST vs Stomp
• In-browser messaging (Ajax vs Web Sockets)
• Mobile messaging using MQTT
• Striking the balance
3
CamelOne 2013
CamelOne
Messaging for Web
• Connect from any web application backend
(Ruby, PHP, Python, …)
• Connect directly from the browser (AJAX, Web
Sockets)
• The main requirement is simplicity
4
CamelOne 2013
CamelOne
What’s wrong with Http?
• Nothing at all!
• Ideal for simple request-reply communication
• Lacks semantics for publish-subscribe and
point-to-point communication
5
CamelOne 2013
CamelOne
Limitations
• Pull based protocol
• Easy simple producing
• There’s no concept of consumer or subscription
• There’s no concept of transactions
6
CamelOne 2013
CamelOne
Pull Consuming
• HTTP techniques
• Long polling
• Comet
• Maintain a state
• Session
• ClientID
7
CamelOne 2013
CamelOne
Push Consuming
• Web Hooks – http://webhooks.org
• Provide a callback (HTTP URL) to be called on
event
• Trigger callback on every message
8
CamelOne 2013
CamelOne Camel HTTP
component
9
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring”>
<route>
<from uri="activemq:topic:events"/>
<to uri="http://mysite.com/events"/>
</route>
</camelContext>
• HawtIO – http://hawt.io
• Missing API for dynamically managing
subscribers
CamelOne 2013
CamelOne
Stomp – what it is?
• http://stomp.github.com
• Simple Text Orientated Messaging Protocol
• HTTP for the messaging realm
10
CamelOne 2013
CamelOne
Stomp – basics
• Very simple, so it’s easy to write clients and
servers in practically any language
• A lot of client APIs in C, Java, Ruby, Pyhton, JS,
PHP
• Implemented by ActiveMQ, Apollo, HornetQ,
RabbitMQ
11
CamelOne 2013
CamelOne
Stomp - Protocol
• Text based headers,
similar to HTTP
• Can transport binary
bodies
• Frame command for
every messaging
concept, like
CONNECT, MESSAGE,
SUBSCRIBE, ACK, etc.
12
MESSAGE
subscription:0
message-id:007
destination:/queue/a
content-type:text/plain
hello queue a^@
CamelOne 2013
CamelOne
Stomp + ActiveMQ
• Available transports
• NIO implementation for better scalability
• SSL for secure communication
13
<transportConnectors>
<transportConnector name=”stomp" uri=”stomp://0.0.0.0:61613"/>
<transportConnector name=”stomp+nio" uri=”stomp+nio://0.0.0.0:61614"/>
<transportConnector name=”stomp+ssl" uri=”stomp+ssl://0.0.0.0:61615"/>
<transportConnector name=”stomp+nio+ssl"
uri=”stomp+nio+ssl://0.0.0.0:61615"/>
</transportConnectors>
CamelOne 2013
CamelOne
Stomp Java Client
• StompJMS -
https://github.com/fusesource/stompjms
• APIs:
• JMS
• Blocking
• Future
• Callback
14
CamelOne 2013
CamelOne
15
Stomp stomp = new Stomp("localhost", 61613);
Future<FutureConnection> future = stomp.connectFuture();
FutureConnection connection = future.await();
CONNECT
host:localhost
accept-version:1.1
CONNECTED
heart-beat:0,0
session:ID:vidra.local-56933-1369046267671-2:1
server:ActiveMQ/5.9-SNAPSHOT
version:1.1
CamelOne 2013
CamelOne
16
StompFrame frame = new StompFrame(SEND);
frame.addHeader(DESTINATION, StompFrame.encodeHeader("/queue/test"));
frame.addHeader(MESSAGE_ID, StompFrame.encodeHeader("test"));
frame.content(new Buffer("Important Message".getBytes("UTF-8")));
Future<Void> sendFuture = connection.send(frame);
sendFuture.await();
SEND
message-id:test
destination:/queue/test
content-length:17
Important Message
CamelOne 2013
CamelOne
17
StompFrame disconnect = new StompFrame(DISCONNECT);
Future<Void> disconnectFuture = connection.send(disconnect);
disconnectFuture.await();
DISCONNECT
CamelOne 2013
CamelOne
18
Stomp stomp = new Stomp("localhost", 61613);
Future<FutureConnection> future = stomp.connectFuture();
FutureConnection connection = future.await();
CONNECT
host:localhost
accept-version:1.1
CONNECTED
heart-beat:0,0
session:ID:vidra.local-56933-1369046267671-2:1
server:ActiveMQ/5.9-SNAPSHOT
version:1.1
CamelOne 2013
CamelOne
19
Future<StompFrame> receiveFuture = connection.receive();
StompFrame frame = new StompFrame(SUBSCRIBE);
frame.addHeader(DESTINATION, StompFrame.encodeHeader("/queue/test"));
AsciiBuffer id = connection.nextId();
frame.addHeader(ID, id);
Future<StompFrame> response = connection.request(frame);
response.await();
SUBSCRIBE
receipt:2
destination:/queue/test
id:1
RECEIPT
receipt-id:2
CamelOne 2013
CamelOne
20
StompFrame received = receiveFuture.await();
System.out.println(received.content());
MESSAGE
message-id:ID:vidra.local-56933-1369046267671-2:1:-1:1:1
destination:/queue/test
timestamp:1369046474700
expires:0
subscription:1
content-length:17
priority:4
Important Message
CamelOne 2013
CamelOne
21
StompFrame unsubscribe = new StompFrame(UNSUBSCRIBE);
unsubscribe.addHeader(ID, id);
Future<Void> unsubscribeFuture = connection.send(unsubscribe);
unsubscribeFuture.await();
UNSUBSCRIBE
id:1
CamelOne 2013
CamelOne
22
StompFrame disconnect = new StompFrame(DISCONNECT);
Future<Void> disconnectFuture = connection.send(disconnect);
disconnectFuture.await();
DISCONNECT
CamelOne 2013
CamelOne
Advanced Stomp
• Ack modes
• Transactions
• Reliable messaging
• Protocol Negotiations
• Heart-beating
23
CamelOne 2013
CamelOne
Stomp and ActiveMQ
• Queues and Topics
• Reliable Messaging
• Temporary destinations
• Durable topic subscribers
• Destination wildcards
• Message selectors
24
CamelOne 2013
CamelOne
Stomp and ActiveMQ
• Message expiration
• Composite destinations
• Priority consumers
• Exclusive consumers
25
CamelOne 2013
CamelOne
In-browser Messaging
• Use JavaScript to produce and consume
messages directly from the browser
• We need to leverage existing web technologies
like Ajax and Web Sockets
• We need a web server that’s able to
communicate with the broker
26
CamelOne 2013
CamelOne
Ajax
• Old-school way
• Comes bundled with ActiveMQ distribution
27
CamelOne 2013
CamelOne
Ajax – explained
• Requires additional servlet as an intermediary
between broker and clients
• POST to send messages
• Jetty continuations to receive messages
28
CamelOne 2013
CamelOne
Ajax – Example
29
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/amq_jquery_adapter.js"></script>
<script type="text/javascript" src="js/amq.js"></script>
<script type="text/javascript">
var amq = org.activemq.Amq;
amq.init({
uri: 'amq',
logging: true,
timeout: 20
});
</script>
CamelOne 2013
CamelOne
Ajax – Example
30
amq.sendMessage(”queue://TEST”, “Important Message!”);
var myHandler =
{
rcvMessage: function(message)
{
console.log(“Received message: ” + message);
}
};
amq.addListener(“myListener”, “queue://TEST”, myHandler.rcvMessage);
CamelOne 2013
CamelOne
WebSocket
• Evolution over Ajax and Comet
• Defines a “socket” – permanent duplex
connection – between browser and server
• Server and browser can exchange messages
31
CamelOne 2013
CamelOne
WebSocket
• Fully standardized and part of HTML5 spec
• Protocol – standardized by IETF
• API – standardized by W3C
• Supported by most modern web servers and
browsers
32
CamelOne 2013
CamelOne
WebSocket Example
33
var connection = new WebSocket("ws://localhost:8161");
connection.onopen = function() {
console.log("Connection opened!");
};
connection.onmessage = function(msg) {
console.log("Received Message: " + msg.data);
};
connection.onerror = function(error) {
console.log("Error occured: " + error);
}
connection.onclose = function(evt) {
console.log("Connection closed!");
};
connection.send("Important Message!");
connection.close();
CamelOne 2013
CamelOne
WebSocket + ActiveMQ
• WebSocket is a plain socket – like a raw TCP
• We need a protocol on top of it to use all
concepts of messaging and connect to broker
• WebSocket+Stomp ideal combination!
34
CamelOne 2013
CamelOne
WebSocket + ActiveMQ
• New ws and wss transports
• wss transport needs SSL context configuration
35
<transportConnectors>
<transportConnector name="websocket" uri="ws://0.0.0.0:61613"/>
<transportConnector name="secure_websocket" uri="wss://0.0.0.0:61614"/>
</transportConnectors>
CamelOne 2013
CamelOne
stomp-websocket
• Client side library stomp-websocket
• http://github.com/jmesnil/stomp-websocket
• Supports Stomp 1.1
• Not a “pure” Stomp as it requires WebSocket
handshake
36
CamelOne 2013
CamelOne stomp-websocket
Example
37
var client = Stomp.client("ws://localhost:61614");
var connected = false;
client.connect("admin", "admin", function() {
connected = true;
client.subscribe("/queue/test", function(message) {
console.log("Received message " + message);
}
});
if (connected) {
client.send("/queue/test", {priority: 9}, "Important Message!");
}
if (connected) {
client.disconnect();
}
CamelOne 2013
CamelOne
Messaging for Mobile
• Different set of requirements
• Low bandwidth network
• Small footprint
• Low power usage
38
CamelOne 2013
CamelOne
MQTT
• http://mqtt.org/ - MQ Telemetry Transport
• IoT (Internet of Things) protocol
• Efficient binary protocol
• Developed by IBM for embedded devices
telemetry
39
CamelOne 2013
CamelOne
MQTT Features
• Low bandwidth
• Smallest frame 2 bytes
• Unreliable networks
• Small footprint
40
CamelOne 2013
CamelOne
MQTT for mobile
• Efficient battery usage - Power Profiliing: MQTT
on Android -
http://stephendnicholas.com/archives/219
• Ideal for native mobile applications
• Usecase: Facebook messanger
• Phone-to-phone delivery in milliseconds, rather than
seconds
• Without killing battery life
41
CamelOne 2013
CamelOne
MQTT
• Publish/subscribe protocol – topics only
• 3 QoS Options:
• At Most Once – message loss might occur
• At Least Once – duplicates might occur
• Exactly Once – guaranteed delivery
42
CamelOne 2013
CamelOne
MQTT + ActiveMQ
• Available transports
• NIO implementation for better scalability
• SSL for secure communication
43
<transportConnectors>
<transportConnector name=”mqtt" uri=”mqtt://0.0.0.0:1883"/>
<transportConnector name=”mqtt+nio" uri=”mqtt+nio://0.0.0.0:1884"/>
<transportConnector name=”mqtt+ssl" uri=”mqtt+ssl://0.0.0.0:1885"/>
<transportConnector name=”mqtt+nio+ssl"
uri=”mqtt+nio+ssl://0.0.0.0:1886"/>
</transportConnectors>
CamelOne 2013
CamelOne
MQTT client
• mqtt-client https://github.com/fusesource/mqtt-
client
• APIs:
• Blocking
• Callback
• Future
44
CamelOne 2013
CamelOne
MQTT Example
45
MQTT mqtt = new MQTT();
mqtt.setHost("localhost", 1883);
final CallbackConnection connection = mqtt.callbackConnection();
CamelOne 2013
CamelOne
MQTT Example
46
connection.connect(new Callback<Void>() {
public void onSuccess(Void value) {
connection.publish("test",
"Important Message!".getBytes(),
QoS.AT_LEAST_ONCE,
false,
null
);
}
public void onFailure(Throwable value) {
connection.disconnect(null);
}
});
CamelOne 2013
CamelOne
MQTT Example
47
final Promise<Buffer> result = new Promise<Buffer>();
connection.listener(new Listener() {
public void onConnected() {}
public void onDisconnected() {}
public void onPublish(UTF8Buffer topic, Buffer body,
Runnable ack) {
result.onSuccess(body);
ack.run();
}
public void onFailure(Throwable value) {
result.onFailure(value);
connection.disconnect(null);
}
});
LOG.info("Received: " + result.await(5, TimeUnit.MINUTES));
CamelOne 2013
CamelOne
MQTT Example
48
connection.connect(new Callback<Void>() {
public void onSuccess(Void aVoid) {
Topic[] topics = {
new Topic(utf8("test"), QoS.AT_LEAST_ONCE)
};
connection.subscribe(topics, null);
}
public void onFailure(Throwable value) {
connection.disconnect(null);
}
});
CamelOne 2013
CamelOne
MQTT Android Example
• https://github.com/jsherman1/android-mqtt-
demo/
49
CamelOne 2013
CamelOne
Striking the Balance
• Lots of possibilities, how to choose right?
• Native mobile apps should consider MQTT
• Do you need live updates in your browser?
• WebSockets ideal for HTML5 apps with limited
number of users that needs instant update
• For everyone else, there's backend messaging
50
CamelOne 2013
CamelOne
Stomp pitfall
• Short-lived connections
• Every page view, open a new connection to the
broker
• Puts heavy load on the broker
• Eliminates all advance messaging mechanisms
– message prefetches, producer flow control,
etc.
51
CamelOne 2013
CamelOne
Stomp configuration
52
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry queue=">" producerFlowControl="false">
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
<transportConnectors>
<transportConnector name="stomp+nio"
uri="stomp+nio://0.0.0.0:61613?transport.closeAsync=false"/>
</transportConnectors>
CamelOne 2013
CamelOne
Conclusion
• Messaging is not the thing of the enterprise
anymore
• Things want to get integrated
• We have technology to do that TODAY!
53
CamelOne 2013
CamelOne
AMA
• Links
• Stomp - http://stomp.github.com
• https://github.com/fusesource/stompjms
• MQTT – http://mqtt.org
• https://github.com/fusesource/mqtt-client
• Blog: http://sensatic.net
• Twitter: http://twitter.com/dejanb
54

More Related Content

What's hot

Kafka basics
Kafka basicsKafka basics
Integrating microservices with apache camel on kubernetes
Integrating microservices with apache camel on kubernetesIntegrating microservices with apache camel on kubernetes
Integrating microservices with apache camel on kubernetes
Claus Ibsen
 
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB)
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB)Apache Kafka vs. Integration Middleware (MQ, ETL, ESB)
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB)
Kai Wähner
 
Integrating Microservices with Apache Camel
Integrating Microservices with Apache CamelIntegrating Microservices with Apache Camel
Integrating Microservices with Apache Camel
Christian Posta
 
High throughput data replication over RAFT
High throughput data replication over RAFTHigh throughput data replication over RAFT
High throughput data replication over RAFT
DataWorks Summit
 
Deploying OpenStack Object Storage (Swift)
Deploying OpenStack Object Storage (Swift)Deploying OpenStack Object Storage (Swift)
Deploying OpenStack Object Storage (Swift)
Juan José Martínez
 
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
mumrah
 
Becoming an AWS Policy Ninja using AWS IAM - AWS Summit Tel Aviv 2017
Becoming an AWS Policy Ninja using AWS IAM - AWS Summit Tel Aviv 2017Becoming an AWS Policy Ninja using AWS IAM - AWS Summit Tel Aviv 2017
Becoming an AWS Policy Ninja using AWS IAM - AWS Summit Tel Aviv 2017
Amazon Web Services
 
Dataflow with Apache NiFi - Apache NiFi Meetup - 2016 Hadoop Summit - San Jose
Dataflow with Apache NiFi - Apache NiFi Meetup - 2016 Hadoop Summit - San JoseDataflow with Apache NiFi - Apache NiFi Meetup - 2016 Hadoop Summit - San Jose
Dataflow with Apache NiFi - Apache NiFi Meetup - 2016 Hadoop Summit - San Jose
Aldrin Piri
 
Efficient Schemas in Motion with Kafka and Schema Registry
Efficient Schemas in Motion with Kafka and Schema RegistryEfficient Schemas in Motion with Kafka and Schema Registry
Efficient Schemas in Motion with Kafka and Schema Registry
Pat Patterson
 
Apache Knox - Hadoop Security Swiss Army Knife
Apache Knox - Hadoop Security Swiss Army KnifeApache Knox - Hadoop Security Swiss Army Knife
Apache Knox - Hadoop Security Swiss Army Knife
DataWorks Summit
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic Architecture
Paul Mooney
 
Four Things to Know About Reliable Spark Streaming with Typesafe and Databricks
Four Things to Know About Reliable Spark Streaming with Typesafe and DatabricksFour Things to Know About Reliable Spark Streaming with Typesafe and Databricks
Four Things to Know About Reliable Spark Streaming with Typesafe and Databricks
Legacy Typesafe (now Lightbend)
 
ActiveMQ In Action
ActiveMQ In ActionActiveMQ In Action
ActiveMQ In Action
Bruce Snyder
 
Apache Ambari: Past, Present, Future
Apache Ambari: Past, Present, FutureApache Ambari: Past, Present, Future
Apache Ambari: Past, Present, Future
Hortonworks
 
Principles of microservices XP Days Ukraine
Principles of microservices   XP Days UkrainePrinciples of microservices   XP Days Ukraine
Principles of microservices XP Days Ukraine
Sam Newman
 
마이크로서비스를 위한 AWS 아키텍처 패턴 및 모범 사례 - AWS Summit Seoul 2017
마이크로서비스를 위한 AWS 아키텍처 패턴 및 모범 사례 - AWS Summit Seoul 2017마이크로서비스를 위한 AWS 아키텍처 패턴 및 모범 사례 - AWS Summit Seoul 2017
마이크로서비스를 위한 AWS 아키텍처 패턴 및 모범 사례 - AWS Summit Seoul 2017
Amazon Web Services Korea
 
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...
Timothy Spann
 
[Games on AWS 2019] AWS 사용자를 위한 만랩 달성 트랙 | AWS에서 분산 서비스 거부 공격(DDoS)을 고민하지 않는 ...
[Games on AWS 2019] AWS 사용자를 위한 만랩 달성 트랙 | AWS에서 분산 서비스 거부 공격(DDoS)을 고민하지 않는 ...[Games on AWS 2019] AWS 사용자를 위한 만랩 달성 트랙 | AWS에서 분산 서비스 거부 공격(DDoS)을 고민하지 않는 ...
[Games on AWS 2019] AWS 사용자를 위한 만랩 달성 트랙 | AWS에서 분산 서비스 거부 공격(DDoS)을 고민하지 않는 ...
Amazon Web Services Korea
 
Dataflow with Apache NiFi
Dataflow with Apache NiFiDataflow with Apache NiFi
Dataflow with Apache NiFi
DataWorks Summit/Hadoop Summit
 

What's hot (20)

Kafka basics
Kafka basicsKafka basics
Kafka basics
 
Integrating microservices with apache camel on kubernetes
Integrating microservices with apache camel on kubernetesIntegrating microservices with apache camel on kubernetes
Integrating microservices with apache camel on kubernetes
 
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB)
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB)Apache Kafka vs. Integration Middleware (MQ, ETL, ESB)
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB)
 
Integrating Microservices with Apache Camel
Integrating Microservices with Apache CamelIntegrating Microservices with Apache Camel
Integrating Microservices with Apache Camel
 
High throughput data replication over RAFT
High throughput data replication over RAFTHigh throughput data replication over RAFT
High throughput data replication over RAFT
 
Deploying OpenStack Object Storage (Swift)
Deploying OpenStack Object Storage (Swift)Deploying OpenStack Object Storage (Swift)
Deploying OpenStack Object Storage (Swift)
 
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
 
Becoming an AWS Policy Ninja using AWS IAM - AWS Summit Tel Aviv 2017
Becoming an AWS Policy Ninja using AWS IAM - AWS Summit Tel Aviv 2017Becoming an AWS Policy Ninja using AWS IAM - AWS Summit Tel Aviv 2017
Becoming an AWS Policy Ninja using AWS IAM - AWS Summit Tel Aviv 2017
 
Dataflow with Apache NiFi - Apache NiFi Meetup - 2016 Hadoop Summit - San Jose
Dataflow with Apache NiFi - Apache NiFi Meetup - 2016 Hadoop Summit - San JoseDataflow with Apache NiFi - Apache NiFi Meetup - 2016 Hadoop Summit - San Jose
Dataflow with Apache NiFi - Apache NiFi Meetup - 2016 Hadoop Summit - San Jose
 
Efficient Schemas in Motion with Kafka and Schema Registry
Efficient Schemas in Motion with Kafka and Schema RegistryEfficient Schemas in Motion with Kafka and Schema Registry
Efficient Schemas in Motion with Kafka and Schema Registry
 
Apache Knox - Hadoop Security Swiss Army Knife
Apache Knox - Hadoop Security Swiss Army KnifeApache Knox - Hadoop Security Swiss Army Knife
Apache Knox - Hadoop Security Swiss Army Knife
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic Architecture
 
Four Things to Know About Reliable Spark Streaming with Typesafe and Databricks
Four Things to Know About Reliable Spark Streaming with Typesafe and DatabricksFour Things to Know About Reliable Spark Streaming with Typesafe and Databricks
Four Things to Know About Reliable Spark Streaming with Typesafe and Databricks
 
ActiveMQ In Action
ActiveMQ In ActionActiveMQ In Action
ActiveMQ In Action
 
Apache Ambari: Past, Present, Future
Apache Ambari: Past, Present, FutureApache Ambari: Past, Present, Future
Apache Ambari: Past, Present, Future
 
Principles of microservices XP Days Ukraine
Principles of microservices   XP Days UkrainePrinciples of microservices   XP Days Ukraine
Principles of microservices XP Days Ukraine
 
마이크로서비스를 위한 AWS 아키텍처 패턴 및 모범 사례 - AWS Summit Seoul 2017
마이크로서비스를 위한 AWS 아키텍처 패턴 및 모범 사례 - AWS Summit Seoul 2017마이크로서비스를 위한 AWS 아키텍처 패턴 및 모범 사례 - AWS Summit Seoul 2017
마이크로서비스를 위한 AWS 아키텍처 패턴 및 모범 사례 - AWS Summit Seoul 2017
 
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...
Designing Event-Driven Applications with Apache NiFi, Apache Flink, Apache Sp...
 
[Games on AWS 2019] AWS 사용자를 위한 만랩 달성 트랙 | AWS에서 분산 서비스 거부 공격(DDoS)을 고민하지 않는 ...
[Games on AWS 2019] AWS 사용자를 위한 만랩 달성 트랙 | AWS에서 분산 서비스 거부 공격(DDoS)을 고민하지 않는 ...[Games on AWS 2019] AWS 사용자를 위한 만랩 달성 트랙 | AWS에서 분산 서비스 거부 공격(DDoS)을 고민하지 않는 ...
[Games on AWS 2019] AWS 사용자를 위한 만랩 달성 트랙 | AWS에서 분산 서비스 거부 공격(DDoS)을 고민하지 않는 ...
 
Dataflow with Apache NiFi
Dataflow with Apache NiFiDataflow with Apache NiFi
Dataflow with Apache NiFi
 

Similar to Messaging for Web and Mobile with Apache ActiveMQ

WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
Viktor Gamov
 
HTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the WebHTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the Web
Peter Lubbers
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New Evolution
Allan Huang
 
Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!
jfarcand
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web Sockets
Fahad Golra
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
Ericom Software
 
The HTML5 WebSocket API
The HTML5 WebSocket APIThe HTML5 WebSocket API
The HTML5 WebSocket API
David Lindkvist
 
WebSockets with Spring 4
WebSockets with Spring 4WebSockets with Spring 4
WebSockets with Spring 4
Sergi Almar i Graupera
 
Enhancing Mobile User Experience with WebSocket
Enhancing Mobile User Experience with WebSocketEnhancing Mobile User Experience with WebSocket
Enhancing Mobile User Experience with WebSocket
Mauricio "Maltron" Leal
 
Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010
sullis
 
Building Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsBuilding Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using Websockets
Naresh Chintalcheru
 
Websocket
WebsocketWebsocket
Websocket
艾鍗科技
 
Being HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on PurposeBeing HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on Purpose
Aman Kohli
 
Building Websocket Applications with GlassFish and Grizzly
Building Websocket Applications with GlassFish and GrizzlyBuilding Websocket Applications with GlassFish and Grizzly
Building Websocket Applications with GlassFish and Grizzly
Justin Lee
 
Websocket
WebsocketWebsocket
Camel oneactivemq posta-final
Camel oneactivemq posta-finalCamel oneactivemq posta-final
Camel oneactivemq posta-final
Christian Posta
 
Pushing the web — WebSockets
Pushing the web — WebSocketsPushing the web — WebSockets
Pushing the web — WebSockets
Roland M
 
Real-Time with Flowdock
Real-Time with FlowdockReal-Time with Flowdock
Real-Time with Flowdock
Flowdock
 
Xke - Introduction to Apache Camel
Xke - Introduction to Apache CamelXke - Introduction to Apache Camel
Xke - Introduction to Apache Camel
Alexis Kinsella
 
Js remote conf
Js remote confJs remote conf
Js remote conf
Bart Wood
 

Similar to Messaging for Web and Mobile with Apache ActiveMQ (20)

WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
 
HTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the WebHTML5 WebSocket: The New Network Stack for the Web
HTML5 WebSocket: The New Network Stack for the Web
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New Evolution
 
Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web Sockets
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
 
The HTML5 WebSocket API
The HTML5 WebSocket APIThe HTML5 WebSocket API
The HTML5 WebSocket API
 
WebSockets with Spring 4
WebSockets with Spring 4WebSockets with Spring 4
WebSockets with Spring 4
 
Enhancing Mobile User Experience with WebSocket
Enhancing Mobile User Experience with WebSocketEnhancing Mobile User Experience with WebSocket
Enhancing Mobile User Experience with WebSocket
 
Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010Programming WebSockets - OSCON 2010
Programming WebSockets - OSCON 2010
 
Building Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsBuilding Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using Websockets
 
Websocket
WebsocketWebsocket
Websocket
 
Being HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on PurposeBeing HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on Purpose
 
Building Websocket Applications with GlassFish and Grizzly
Building Websocket Applications with GlassFish and GrizzlyBuilding Websocket Applications with GlassFish and Grizzly
Building Websocket Applications with GlassFish and Grizzly
 
Websocket
WebsocketWebsocket
Websocket
 
Camel oneactivemq posta-final
Camel oneactivemq posta-finalCamel oneactivemq posta-final
Camel oneactivemq posta-final
 
Pushing the web — WebSockets
Pushing the web — WebSocketsPushing the web — WebSockets
Pushing the web — WebSockets
 
Real-Time with Flowdock
Real-Time with FlowdockReal-Time with Flowdock
Real-Time with Flowdock
 
Xke - Introduction to Apache Camel
Xke - Introduction to Apache CamelXke - Introduction to Apache Camel
Xke - Introduction to Apache Camel
 
Js remote conf
Js remote confJs remote conf
Js remote conf
 

More from dejanb

How is this sausage made
How is this sausage madeHow is this sausage made
How is this sausage made
dejanb
 
Messaging for the cloud
Messaging for the cloudMessaging for the cloud
Messaging for the cloud
dejanb
 
Scaling out eclipse hono
Scaling out eclipse honoScaling out eclipse hono
Scaling out eclipse hono
dejanb
 
Building Open Source IoT Cloud
Building Open Source IoT CloudBuilding Open Source IoT Cloud
Building Open Source IoT Cloud
dejanb
 
Messaging for IoT
Messaging for IoTMessaging for IoT
Messaging for IoT
dejanb
 
Introduction to ActiveMQ Apollo
Introduction to ActiveMQ ApolloIntroduction to ActiveMQ Apollo
Introduction to ActiveMQ Apollo
dejanb
 
Deploying FuseMQ with Fuse Fabric
Deploying FuseMQ with Fuse FabricDeploying FuseMQ with Fuse Fabric
Deploying FuseMQ with Fuse Fabric
dejanb
 
Advanced messaging with Apache ActiveMQ
Advanced messaging with Apache ActiveMQAdvanced messaging with Apache ActiveMQ
Advanced messaging with Apache ActiveMQ
dejanb
 
Apache ActiveMQ - Enterprise messaging in action
Apache ActiveMQ - Enterprise messaging in actionApache ActiveMQ - Enterprise messaging in action
Apache ActiveMQ - Enterprise messaging in action
dejanb
 

More from dejanb (9)

How is this sausage made
How is this sausage madeHow is this sausage made
How is this sausage made
 
Messaging for the cloud
Messaging for the cloudMessaging for the cloud
Messaging for the cloud
 
Scaling out eclipse hono
Scaling out eclipse honoScaling out eclipse hono
Scaling out eclipse hono
 
Building Open Source IoT Cloud
Building Open Source IoT CloudBuilding Open Source IoT Cloud
Building Open Source IoT Cloud
 
Messaging for IoT
Messaging for IoTMessaging for IoT
Messaging for IoT
 
Introduction to ActiveMQ Apollo
Introduction to ActiveMQ ApolloIntroduction to ActiveMQ Apollo
Introduction to ActiveMQ Apollo
 
Deploying FuseMQ with Fuse Fabric
Deploying FuseMQ with Fuse FabricDeploying FuseMQ with Fuse Fabric
Deploying FuseMQ with Fuse Fabric
 
Advanced messaging with Apache ActiveMQ
Advanced messaging with Apache ActiveMQAdvanced messaging with Apache ActiveMQ
Advanced messaging with Apache ActiveMQ
 
Apache ActiveMQ - Enterprise messaging in action
Apache ActiveMQ - Enterprise messaging in actionApache ActiveMQ - Enterprise messaging in action
Apache ActiveMQ - Enterprise messaging in action
 

Recently uploaded

Quantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLMQuantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLM
Vijayananda Mohire
 
Choose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presenceChoose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presence
rajancomputerfbd
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
Mark Billinghurst
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
ishalveerrandhawa1
 
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
ArgaBisma
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
Stephanie Beckett
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
BookNet Canada
 
Coordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar SlidesCoordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar Slides
Safe Software
 
20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf
Sally Laouacheria
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
Adam Dunkels
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
Matthew Sinclair
 
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Bert Blevins
 
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
Toru Tamaki
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
huseindihon
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Chris Swan
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
Yevgen Sysoyev
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
Enterprise Wired
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
Matthew Sinclair
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
Eric D. Schabell
 
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptxRPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
SynapseIndia
 

Recently uploaded (20)

Quantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLMQuantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLM
 
Choose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presenceChoose our Linux Web Hosting for a seamless and successful online presence
Choose our Linux Web Hosting for a seamless and successful online presence
 
Research Directions for Cross Reality Interfaces
Research Directions for Cross Reality InterfacesResearch Directions for Cross Reality Interfaces
Research Directions for Cross Reality Interfaces
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
 
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
 
Coordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar SlidesCoordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar Slides
 
20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf20240702 Présentation Plateforme GenAI.pdf
20240702 Présentation Plateforme GenAI.pdf
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
 
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
Understanding Insider Security Threats: Types, Examples, Effects, and Mitigat...
 
論文紹介���A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
論文紹介:A Systematic Survey of Prompt Engineering on Vision-Language Foundation ...
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
 
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptxRPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
 

Messaging for Web and Mobile with Apache ActiveMQ

  • 1. CamelOne 2013 June 10-11 2013 Boston, MA Messaging for web and mobile with Apache ActiveMQ By Bosanac Dejan 1
  • 2. CamelOne 2013 CamelOne 2 Bosanac Dejan? • Senior Sofware Engineer at RedHat • Apache ActiveMQ committer and PMC member • Co-author of ActiveMQ in Action • Blog – http://sensatic.net • Twitter – http://twitter.com/dejanb
  • 3. CamelOne 2013 CamelOne Agenda • Challenges of web messaging • REST vs Stomp • In-browser messaging (Ajax vs Web Sockets) • Mobile messaging using MQTT • Striking the balance 3
  • 4. CamelOne 2013 CamelOne Messaging for Web • Connect from any web application backend (Ruby, PHP, Python, …) • Connect directly from the browser (AJAX, Web Sockets) • The main requirement is simplicity 4
  • 5. CamelOne 2013 CamelOne What’s wrong with Http? • Nothing at all! • Ideal for simple request-reply communication • Lacks semantics for publish-subscribe and point-to-point communication 5
  • 6. CamelOne 2013 CamelOne Limitations • Pull based protocol • Easy simple producing • There’s no concept of consumer or subscription • There’s no concept of transactions 6
  • 7. CamelOne 2013 CamelOne Pull Consuming • HTTP techniques • Long polling • Comet • Maintain a state • Session • ClientID 7
  • 8. CamelOne 2013 CamelOne Push Consuming • Web Hooks – http://webhooks.org • Provide a callback (HTTP URL) to be called on event • Trigger callback on every message 8
  • 9. CamelOne 2013 CamelOne Camel HTTP component 9 <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring”> <route> <from uri="activemq:topic:events"/> <to uri="http://mysite.com/events"/> </route> </camelContext> • HawtIO – http://hawt.io • Missing API for dynamically managing subscribers
  • 10. CamelOne 2013 CamelOne Stomp – what it is? • http://stomp.github.com • Simple Text Orientated Messaging Protocol • HTTP for the messaging realm 10
  • 11. CamelOne 2013 CamelOne Stomp – basics • Very simple, so it’s easy to write clients and servers in practically any language • A lot of client APIs in C, Java, Ruby, Pyhton, JS, PHP • Implemented by ActiveMQ, Apollo, HornetQ, RabbitMQ 11
  • 12. CamelOne 2013 CamelOne Stomp - Protocol • Text based headers, similar to HTTP • Can transport binary bodies • Frame command for every messaging concept, like CONNECT, MESSAGE, SUBSCRIBE, ACK, etc. 12 MESSAGE subscription:0 message-id:007 destination:/queue/a content-type:text/plain hello queue a^@
  • 13. CamelOne 2013 CamelOne Stomp + ActiveMQ • Available transports • NIO implementation for better scalability • SSL for secure communication 13 <transportConnectors> <transportConnector name=”stomp" uri=”stomp://0.0.0.0:61613"/> <transportConnector name=”stomp+nio" uri=”stomp+nio://0.0.0.0:61614"/> <transportConnector name=”stomp+ssl" uri=”stomp+ssl://0.0.0.0:61615"/> <transportConnector name=”stomp+nio+ssl" uri=”stomp+nio+ssl://0.0.0.0:61615"/> </transportConnectors>
  • 14. CamelOne 2013 CamelOne Stomp Java Client • StompJMS - https://github.com/fusesource/stompjms • APIs: • JMS • Blocking • Future • Callback 14
  • 15. CamelOne 2013 CamelOne 15 Stomp stomp = new Stomp("localhost", 61613); Future<FutureConnection> future = stomp.connectFuture(); FutureConnection connection = future.await(); CONNECT host:localhost accept-version:1.1 CONNECTED heart-beat:0,0 session:ID:vidra.local-56933-1369046267671-2:1 server:ActiveMQ/5.9-SNAPSHOT version:1.1
  • 16. CamelOne 2013 CamelOne 16 StompFrame frame = new StompFrame(SEND); frame.addHeader(DESTINATION, StompFrame.encodeHeader("/queue/test")); frame.addHeader(MESSAGE_ID, StompFrame.encodeHeader("test")); frame.content(new Buffer("Important Message".getBytes("UTF-8"))); Future<Void> sendFuture = connection.send(frame); sendFuture.await(); SEND message-id:test destination:/queue/test content-length:17 Important Message
  • 17. CamelOne 2013 CamelOne 17 StompFrame disconnect = new StompFrame(DISCONNECT); Future<Void> disconnectFuture = connection.send(disconnect); disconnectFuture.await(); DISCONNECT
  • 18. CamelOne 2013 CamelOne 18 Stomp stomp = new Stomp("localhost", 61613); Future<FutureConnection> future = stomp.connectFuture(); FutureConnection connection = future.await(); CONNECT host:localhost accept-version:1.1 CONNECTED heart-beat:0,0 session:ID:vidra.local-56933-1369046267671-2:1 server:ActiveMQ/5.9-SNAPSHOT version:1.1
  • 19. CamelOne 2013 CamelOne 19 Future<StompFrame> receiveFuture = connection.receive(); StompFrame frame = new StompFrame(SUBSCRIBE); frame.addHeader(DESTINATION, StompFrame.encodeHeader("/queue/test")); AsciiBuffer id = connection.nextId(); frame.addHeader(ID, id); Future<StompFrame> response = connection.request(frame); response.await(); SUBSCRIBE receipt:2 destination:/queue/test id:1 RECEIPT receipt-id:2
  • 20. CamelOne 2013 CamelOne 20 StompFrame received = receiveFuture.await(); System.out.println(received.content()); MESSAGE message-id:ID:vidra.local-56933-1369046267671-2:1:-1:1:1 destination:/queue/test timestamp:1369046474700 expires:0 subscription:1 content-length:17 priority:4 Important Message
  • 21. CamelOne 2013 CamelOne 21 StompFrame unsubscribe = new StompFrame(UNSUBSCRIBE); unsubscribe.addHeader(ID, id); Future<Void> unsubscribeFuture = connection.send(unsubscribe); unsubscribeFuture.await(); UNSUBSCRIBE id:1
  • 22. CamelOne 2013 CamelOne 22 StompFrame disconnect = new StompFrame(DISCONNECT); Future<Void> disconnectFuture = connection.send(disconnect); disconnectFuture.await(); DISCONNECT
  • 23. CamelOne 2013 CamelOne Advanced Stomp • Ack modes • Transactions • Reliable messaging • Protocol Negotiations • Heart-beating 23
  • 24. CamelOne 2013 CamelOne Stomp and ActiveMQ • Queues and Topics • Reliable Messaging • Temporary destinations • Durable topic subscribers • Destination wildcards • Message selectors 24
  • 25. CamelOne 2013 CamelOne Stomp and ActiveMQ • Message expiration • Composite destinations • Priority consumers • Exclusive consumers 25
  • 26. CamelOne 2013 CamelOne In-browser Messaging • Use JavaScript to produce and consume messages directly from the browser • We need to leverage existing web technologies like Ajax and Web Sockets • We need a web server that’s able to communicate with the broker 26
  • 27. CamelOne 2013 CamelOne Ajax • Old-school way • Comes bundled with ActiveMQ distribution 27
  • 28. CamelOne 2013 CamelOne Ajax – explained • Requires additional servlet as an intermediary between broker and clients • POST to send messages • Jetty continuations to receive messages 28
  • 29. CamelOne 2013 CamelOne Ajax – Example 29 <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="js/amq_jquery_adapter.js"></script> <script type="text/javascript" src="js/amq.js"></script> <script type="text/javascript"> var amq = org.activemq.Amq; amq.init({ uri: 'amq', logging: true, timeout: 20 }); </script>
  • 30. CamelOne 2013 CamelOne Ajax – Example 30 amq.sendMessage(”queue://TEST”, “Important Message!”); var myHandler = { rcvMessage: function(message) { console.log(“Received message: ” + message); } }; amq.addListener(“myListener”, “queue://TEST”, myHandler.rcvMessage);
  • 31. CamelOne 2013 CamelOne WebSocket • Evolution over Ajax and Comet • Defines a “socket” – permanent duplex connection – between browser and server • Server and browser can exchange messages 31
  • 32. CamelOne 2013 CamelOne WebSocket • Fully standardized and part of HTML5 spec • Protocol – standardized by IETF • API – standardized by W3C • Supported by most modern web servers and browsers 32
  • 33. CamelOne 2013 CamelOne WebSocket Example 33 var connection = new WebSocket("ws://localhost:8161"); connection.onopen = function() { console.log("Connection opened!"); }; connection.onmessage = function(msg) { console.log("Received Message: " + msg.data); }; connection.onerror = function(error) { console.log("Error occured: " + error); } connection.onclose = function(evt) { console.log("Connection closed!"); }; connection.send("Important Message!"); connection.close();
  • 34. CamelOne 2013 CamelOne WebSocket + ActiveMQ • WebSocket is a plain socket – like a raw TCP • We need a protocol on top of it to use all concepts of messaging and connect to broker • WebSocket+Stomp ideal combination! 34
  • 35. CamelOne 2013 CamelOne WebSocket + ActiveMQ • New ws and wss transports • wss transport needs SSL context configuration 35 <transportConnectors> <transportConnector name="websocket" uri="ws://0.0.0.0:61613"/> <transportConnector name="secure_websocket" uri="wss://0.0.0.0:61614"/> </transportConnectors>
  • 36. CamelOne 2013 CamelOne stomp-websocket • Client side library stomp-websocket • http://github.com/jmesnil/stomp-websocket • Supports Stomp 1.1 • Not a “pure” Stomp as it requires WebSocket handshake 36
  • 37. CamelOne 2013 CamelOne stomp-websocket Example 37 var client = Stomp.client("ws://localhost:61614"); var connected = false; client.connect("admin", "admin", function() { connected = true; client.subscribe("/queue/test", function(message) { console.log("Received message " + message); } }); if (connected) { client.send("/queue/test", {priority: 9}, "Important Message!"); } if (connected) { client.disconnect(); }
  • 38. CamelOne 2013 CamelOne Messaging for Mobile • Different set of requirements • Low bandwidth network • Small footprint • Low power usage 38
  • 39. CamelOne 2013 CamelOne MQTT • http://mqtt.org/ - MQ Telemetry Transport • IoT (Internet of Things) protocol • Efficient binary protocol • Developed by IBM for embedded devices telemetry 39
  • 40. CamelOne 2013 CamelOne MQTT Features • Low bandwidth • Smallest frame 2 bytes • Unreliable networks • Small footprint 40
  • 41. CamelOne 2013 CamelOne MQTT for mobile • Efficient battery usage - Power Profiliing: MQTT on Android - http://stephendnicholas.com/archives/219 • Ideal for native mobile applications • Usecase: Facebook messanger • Phone-to-phone delivery in milliseconds, rather than seconds • Without killing battery life 41
  • 42. CamelOne 2013 CamelOne MQTT • Publish/subscribe protocol – topics only • 3 QoS Options: • At Most Once – message loss might occur • At Least Once – duplicates might occur • Exactly Once – guaranteed delivery 42
  • 43. CamelOne 2013 CamelOne MQTT + ActiveMQ • Available transports • NIO implementation for better scalability • SSL for secure communication 43 <transportConnectors> <transportConnector name=”mqtt" uri=”mqtt://0.0.0.0:1883"/> <transportConnector name=”mqtt+nio" uri=”mqtt+nio://0.0.0.0:1884"/> <transportConnector name=”mqtt+ssl" uri=”mqtt+ssl://0.0.0.0:1885"/> <transportConnector name=”mqtt+nio+ssl" uri=”mqtt+nio+ssl://0.0.0.0:1886"/> </transportConnectors>
  • 44. CamelOne 2013 CamelOne MQTT client • mqtt-client https://github.com/fusesource/mqtt- client • APIs: • Blocking • Callback • Future 44
  • 45. CamelOne 2013 CamelOne MQTT Example 45 MQTT mqtt = new MQTT(); mqtt.setHost("localhost", 1883); final CallbackConnection connection = mqtt.callbackConnection();
  • 46. CamelOne 2013 CamelOne MQTT Example 46 connection.connect(new Callback<Void>() { public void onSuccess(Void value) { connection.publish("test", "Important Message!".getBytes(), QoS.AT_LEAST_ONCE, false, null ); } public void onFailure(Throwable value) { connection.disconnect(null); } });
  • 47. CamelOne 2013 CamelOne MQTT Example 47 final Promise<Buffer> result = new Promise<Buffer>(); connection.listener(new Listener() { public void onConnected() {} public void onDisconnected() {} public void onPublish(UTF8Buffer topic, Buffer body, Runnable ack) { result.onSuccess(body); ack.run(); } public void onFailure(Throwable value) { result.onFailure(value); connection.disconnect(null); } }); LOG.info("Received: " + result.await(5, TimeUnit.MINUTES));
  • 48. CamelOne 2013 CamelOne MQTT Example 48 connection.connect(new Callback<Void>() { public void onSuccess(Void aVoid) { Topic[] topics = { new Topic(utf8("test"), QoS.AT_LEAST_ONCE) }; connection.subscribe(topics, null); } public void onFailure(Throwable value) { connection.disconnect(null); } });
  • 49. CamelOne 2013 CamelOne MQTT Android Example • https://github.com/jsherman1/android-mqtt- demo/ 49
  • 50. CamelOne 2013 CamelOne Striking the Balance • Lots of possibilities, how to choose right? • Native mobile apps should consider MQTT • Do you need live updates in your browser? • WebSockets ideal for HTML5 apps with limited number of users that needs instant update • For everyone else, there's backend messaging 50
  • 51. CamelOne 2013 CamelOne Stomp pitfall • Short-lived connections • Every page view, open a new connection to the broker • Puts heavy load on the broker • Eliminates all advance messaging mechanisms – message prefetches, producer flow control, etc. 51
  • 52. CamelOne 2013 CamelOne Stomp configuration 52 <destinationPolicy> <policyMap> <policyEntries> <policyEntry queue=">" producerFlowControl="false"> </policyEntry> </policyEntries> </policyMap> </destinationPolicy> <transportConnectors> <transportConnector name="stomp+nio" uri="stomp+nio://0.0.0.0:61613?transport.closeAsync=false"/> </transportConnectors>
  • 53. CamelOne 2013 CamelOne Conclusion • Messaging is not the thing of the enterprise anymore • Things want to get integrated • We have technology to do that TODAY! 53
  • 54. CamelOne 2013 CamelOne AMA • Links • Stomp - http://stomp.github.com • https://github.com/fusesource/stompjms • MQTT – http://mqtt.org • https://github.com/fusesource/mqtt-client • Blog: http://sensatic.net • Twitter: http://twitter.com/dejanb 54