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

An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
All Things Open
 
How Do I Know I Need a Ledger Database? An Intro to Amazon QLDB: re:Invent 20...
How Do I Know I Need a Ledger Database? An Intro to Amazon QLDB: re:Invent 20...How Do I Know I Need a Ledger Database? An Intro to Amazon QLDB: re:Invent 20...
How Do I Know I Need a Ledger Database? An Intro to Amazon QLDB: re:Invent 20...
Amazon Web Services
 
Model Your Application Domain, Not Your JSON Structures
Model Your Application Domain, Not Your JSON StructuresModel Your Application Domain, Not Your JSON Structures
Model Your Application Domain, Not Your JSON Structures
Markus Lanthaler
 
Understanding Sling Models in AEM
Understanding Sling Models in AEMUnderstanding Sling Models in AEM
Understanding Sling Models in AEM
Accunity Software
 
Web API 2 Token Based Authentication
Web API 2 Token Based AuthenticationWeb API 2 Token Based Authentication
Web API 2 Token Based Authentication
jeremysbrown
 
What is REST?
What is REST?What is REST?
What is REST?
Saeid Zebardast
 
React lecture
React lectureReact lecture
React lecture
Christoffer Noring
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
Claus Ibsen
 
Secure Spring Boot Microservices with Keycloak
Secure Spring Boot Microservices with KeycloakSecure Spring Boot Microservices with Keycloak
Secure Spring Boot Microservices with Keycloak
Red Hat Developers
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template Language
Gabriel Walt
 
ROS 2 Foxy with Eclipse Cyclone DDS | Philly ROS Meetup July 20th 2020
ROS 2 Foxy with Eclipse Cyclone DDS | Philly ROS Meetup July 20th 2020ROS 2 Foxy with Eclipse Cyclone DDS | Philly ROS Meetup July 20th 2020
ROS 2 Foxy with Eclipse Cyclone DDS | Philly ROS Meetup July 20th 2020
Joe Speed
 
Java mission control and java flight recorder
Java mission control and java flight recorderJava mission control and java flight recorder
Java mission control and java flight recorder
Wolfgang Weigend
 
Kafka Retry and DLQ
Kafka Retry and DLQKafka Retry and DLQ
Kafka Retry and DLQ
George Teo
 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
Taras Matyashovsky
 
Intro to React
Intro to ReactIntro to React
Intro to React
Justin Reock
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
Thanh Tuong
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
React
React React
React
중운 박
 
A Deep Dive into Kafka Controller
A Deep Dive into Kafka ControllerA Deep Dive into Kafka Controller
A Deep Dive into Kafka Controller
confluent
 
Why Use React Js A Complete Guide (1).pdf
Why Use React Js A Complete Guide (1).pdfWhy Use React Js A Complete Guide (1).pdf
Why Use React Js A Complete Guide (1).pdf
Katy Slemon
 

What's hot (20)

An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
 
How Do I Know I Need a Ledger Database? An Intro to Amazon QLDB: re:Invent 20...
How Do I Know I Need a Ledger Database? An Intro to Amazon QLDB: re:Invent 20...How Do I Know I Need a Ledger Database? An Intro to Amazon QLDB: re:Invent 20...
How Do I Know I Need a Ledger Database? An Intro to Amazon QLDB: re:Invent 20...
 
Model Your Application Domain, Not Your JSON Structures
Model Your Application Domain, Not Your JSON StructuresModel Your Application Domain, Not Your JSON Structures
Model Your Application Domain, Not Your JSON Structures
 
Understanding Sling Models in AEM
Understanding Sling Models in AEMUnderstanding Sling Models in AEM
Understanding Sling Models in AEM
 
Web API 2 Token Based Authentication
Web API 2 Token Based AuthenticationWeb API 2 Token Based Authentication
Web API 2 Token Based Authentication
 
What is REST?
What is REST?What is REST?
What is REST?
 
React lecture
React lectureReact lecture
React lecture
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
 
Secure Spring Boot Microservices with Keycloak
Secure Spring Boot Microservices with KeycloakSecure Spring Boot Microservices with Keycloak
Secure Spring Boot Microservices with Keycloak
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template Language
 
ROS 2 Foxy with Eclipse Cyclone DDS | Philly ROS Meetup July 20th 2020
ROS 2 Foxy with Eclipse Cyclone DDS | Philly ROS Meetup July 20th 2020ROS 2 Foxy with Eclipse Cyclone DDS | Philly ROS Meetup July 20th 2020
ROS 2 Foxy with Eclipse Cyclone DDS | Philly ROS Meetup July 20th 2020
 
Java mission control and java flight recorder
Java mission control and java flight recorderJava mission control and java flight recorder
Java mission control and java flight recorder
 
Kafka Retry and DLQ
Kafka Retry and DLQKafka Retry and DLQ
Kafka Retry and DLQ
 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
React
React React
React
 
A Deep Dive into Kafka Controller
A Deep Dive into Kafka ControllerA Deep Dive into Kafka Controller
A Deep Dive into Kafka Controller
 
Why Use React Js A Complete Guide (1).pdf
Why Use React Js A Complete Guide (1).pdfWhy Use React Js A Complete Guide (1).pdf
Why Use React Js A Complete Guide (1).pdf
 

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 DevelopersViktor 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 EvolutionAllan Huang
 
Connecting Applications Everywhere with ActiveMQ
Connecting Applications Everywhere with ActiveMQConnecting Applications Everywhere with ActiveMQ
Connecting Applications Everywhere with ActiveMQ
Rob Davies
 
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 2010sullis
 
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-finalChristian Posta
 
Pushing the web — WebSockets
Pushing the web — WebSocketsPushing the web — WebSockets
Pushing the web — WebSocketsRoland 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
 

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
 
Connecting Applications Everywhere with ActiveMQ
Connecting Applications Everywhere with ActiveMQConnecting Applications Everywhere with ActiveMQ
Connecting Applications Everywhere with ActiveMQ
 
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
 

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 actiondejanb
 

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

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 

Recently uploaded (20)

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 

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