SlideShare uma empresa Scribd logo
1 de 54
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

Mais conteúdo relacionado

Mais procurados

Getting Started with Confluent Schema Registry
Getting Started with Confluent Schema RegistryGetting Started with Confluent Schema Registry
Getting Started with Confluent Schema Registryconfluent
 
Everything You Always Wanted to Know About Kafka’s Rebalance Protocol but Wer...
Everything You Always Wanted to Know About Kafka’s Rebalance Protocol but Wer...Everything You Always Wanted to Know About Kafka’s Rebalance Protocol but Wer...
Everything You Always Wanted to Know About Kafka’s Rebalance Protocol but Wer...confluent
 
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...Kai Wähner
 
From Zero to Hero with Kafka Connect
From Zero to Hero with Kafka ConnectFrom Zero to Hero with Kafka Connect
From Zero to Hero with Kafka Connectconfluent
 
Kafka connect 101
Kafka connect 101Kafka connect 101
Kafka connect 101Whiteklay
 
HBase and Hadoop at Adobe
HBase and Hadoop at AdobeHBase and Hadoop at Adobe
HBase and Hadoop at AdobeCosmin Lehene
 
What is Apache Kafka and What is an Event Streaming Platform?
What is Apache Kafka and What is an Event Streaming Platform?What is Apache Kafka and What is an Event Streaming Platform?
What is Apache Kafka and What is an Event Streaming Platform?confluent
 
Kafka Connect & Streams - the ecosystem around Kafka
Kafka Connect & Streams - the ecosystem around KafkaKafka Connect & Streams - the ecosystem around Kafka
Kafka Connect & Streams - the ecosystem around KafkaGuido Schmutz
 
A Modern C++ Kafka API | Kenneth Jia, Morgan Stanley
A Modern C++ Kafka API | Kenneth Jia, Morgan StanleyA Modern C++ Kafka API | Kenneth Jia, Morgan Stanley
A Modern C++ Kafka API | Kenneth Jia, Morgan StanleyHostedbyConfluent
 
Disaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache KafkaDisaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache Kafkaconfluent
 
Deploying Flink on Kubernetes - David Anderson
 Deploying Flink on Kubernetes - David Anderson Deploying Flink on Kubernetes - David Anderson
Deploying Flink on Kubernetes - David AndersonVerverica
 
Kafka Connect and Streams (Concepts, Architecture, Features)
Kafka Connect and Streams (Concepts, Architecture, Features)Kafka Connect and Streams (Concepts, Architecture, Features)
Kafka Connect and Streams (Concepts, Architecture, Features)Kai Wähner
 
Introduction To Flink
Introduction To FlinkIntroduction To Flink
Introduction To FlinkKnoldus Inc.
 
IBM Datapower Security Scenario with JWS & JWE
IBM Datapower Security Scenario with JWS & JWEIBM Datapower Security Scenario with JWS & JWE
IBM Datapower Security Scenario with JWS & JWEsandipg123
 
Kafka and Avro with Confluent Schema Registry
Kafka and Avro with Confluent Schema RegistryKafka and Avro with Confluent Schema Registry
Kafka and Avro with Confluent Schema RegistryJean-Paul Azar
 
Flink Forward Berlin 2017: Patrick Lucas - Flink in Containerland
Flink Forward Berlin 2017: Patrick Lucas - Flink in ContainerlandFlink Forward Berlin 2017: Patrick Lucas - Flink in Containerland
Flink Forward Berlin 2017: Patrick Lucas - Flink in ContainerlandFlink Forward
 
Deep Dive Into Kafka Streams (and the Distributed Stream Processing Engine) (...
Deep Dive Into Kafka Streams (and the Distributed Stream Processing Engine) (...Deep Dive Into Kafka Streams (and the Distributed Stream Processing Engine) (...
Deep Dive Into Kafka Streams (and the Distributed Stream Processing Engine) (...confluent
 

Mais procurados (20)

Getting Started with Confluent Schema Registry
Getting Started with Confluent Schema RegistryGetting Started with Confluent Schema Registry
Getting Started with Confluent Schema Registry
 
Everything You Always Wanted to Know About Kafka’s Rebalance Protocol but Wer...
Everything You Always Wanted to Know About Kafka’s Rebalance Protocol but Wer...Everything You Always Wanted to Know About Kafka’s Rebalance Protocol but Wer...
Everything You Always Wanted to Know About Kafka’s Rebalance Protocol but Wer...
 
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
Architecture patterns for distributed, hybrid, edge and global Apache Kafka d...
 
From Zero to Hero with Kafka Connect
From Zero to Hero with Kafka ConnectFrom Zero to Hero with Kafka Connect
From Zero to Hero with Kafka Connect
 
Apache Kafka at LinkedIn
Apache Kafka at LinkedInApache Kafka at LinkedIn
Apache Kafka at LinkedIn
 
Unified Stream and Batch Processing with Apache Flink
Unified Stream and Batch Processing with Apache FlinkUnified Stream and Batch Processing with Apache Flink
Unified Stream and Batch Processing with Apache Flink
 
Kafka connect 101
Kafka connect 101Kafka connect 101
Kafka connect 101
 
HBase and Hadoop at Adobe
HBase and Hadoop at AdobeHBase and Hadoop at Adobe
HBase and Hadoop at Adobe
 
What is Apache Kafka and What is an Event Streaming Platform?
What is Apache Kafka and What is an Event Streaming Platform?What is Apache Kafka and What is an Event Streaming Platform?
What is Apache Kafka and What is an Event Streaming Platform?
 
Kafka Connect & Streams - the ecosystem around Kafka
Kafka Connect & Streams - the ecosystem around KafkaKafka Connect & Streams - the ecosystem around Kafka
Kafka Connect & Streams - the ecosystem around Kafka
 
A Modern C++ Kafka API | Kenneth Jia, Morgan Stanley
A Modern C++ Kafka API | Kenneth Jia, Morgan StanleyA Modern C++ Kafka API | Kenneth Jia, Morgan Stanley
A Modern C++ Kafka API | Kenneth Jia, Morgan Stanley
 
Disaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache KafkaDisaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache Kafka
 
Apache Kafka Best Practices
Apache Kafka Best PracticesApache Kafka Best Practices
Apache Kafka Best Practices
 
Deploying Flink on Kubernetes - David Anderson
 Deploying Flink on Kubernetes - David Anderson Deploying Flink on Kubernetes - David Anderson
Deploying Flink on Kubernetes - David Anderson
 
Kafka Connect and Streams (Concepts, Architecture, Features)
Kafka Connect and Streams (Concepts, Architecture, Features)Kafka Connect and Streams (Concepts, Architecture, Features)
Kafka Connect and Streams (Concepts, Architecture, Features)
 
Introduction To Flink
Introduction To FlinkIntroduction To Flink
Introduction To Flink
 
IBM Datapower Security Scenario with JWS & JWE
IBM Datapower Security Scenario with JWS & JWEIBM Datapower Security Scenario with JWS & JWE
IBM Datapower Security Scenario with JWS & JWE
 
Kafka and Avro with Confluent Schema Registry
Kafka and Avro with Confluent Schema RegistryKafka and Avro with Confluent Schema Registry
Kafka and Avro with Confluent Schema Registry
 
Flink Forward Berlin 2017: Patrick Lucas - Flink in Containerland
Flink Forward Berlin 2017: Patrick Lucas - Flink in ContainerlandFlink Forward Berlin 2017: Patrick Lucas - Flink in Containerland
Flink Forward Berlin 2017: Patrick Lucas - Flink in Containerland
 
Deep Dive Into Kafka Streams (and the Distributed Stream Processing Engine) (...
Deep Dive Into Kafka Streams (and the Distributed Stream Processing Engine) (...Deep Dive Into Kafka Streams (and the Distributed Stream Processing Engine) (...
Deep Dive Into Kafka Streams (and the Distributed Stream Processing Engine) (...
 

Semelhante a 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 WebPeter 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 ActiveMQRob 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 SocketsFahad 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
 
Enhancing Mobile User Experience with WebSocket
Enhancing Mobile User Experience with WebSocketEnhancing Mobile User Experience with WebSocket
Enhancing Mobile User Experience with WebSocketMauricio "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 WebsocketsNaresh Chintalcheru
 
Being HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on PurposeBeing HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on PurposeAman 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 GrizzlyJustin Lee
 
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 FlowdockFlowdock
 
Xke - Introduction to Apache Camel
Xke - Introduction to Apache CamelXke - Introduction to Apache Camel
Xke - Introduction to Apache CamelAlexis Kinsella
 

Semelhante a 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
 

Mais de dejanb

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

Mais de 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
 

Último

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

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