SlideShare une entreprise Scribd logo
1  sur  51
2013 © Trivadis
BASEL BERN LAUSANNE ZÜRICH DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MÜNCHEN STUTTGART WIEN
JUG Münster Scalable enterprise
applications with JEE7
and beyond
Andy Moncsek
17. April 2013
18.07.2013
JEE to the Max
1
2013 © Trivadis
BASEL BERN LAUSANNE ZÜRICH DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MÜNCHEN STUTTGART WIEN
Andy Moncsek
Consultant for Application Devlopment (Zürich)
Trainer for JavaEE Assembly & Deployment
Contacts: Andy.Moncsek@Trivadis.com
Twitter: @AndyAHCP
2013 © Trivadis
AGENDA
1. Motivation
2. Server Sent Events
3. WebSocket (JSR-356)
4. SSE & WebSockets in Enterprise
 Security
 Loadbalancing / Failover
5. (short) JEE 7 project overview
18.07.2013
JEE to the Max
3
2013 © Trivadis
Motivation
18.07.2013
JEE to the Max
4
JEE 7
what’s new?
2013 © Trivadis
Motivation
18.07.2013
JEE to the Max
5
state: function() { return state; }, always: function() { deferred.done(
arguments ).fail( arguments ); return this; }, then: function( /*
fnDone, fnFail, fnProgress */ ) { var fns = arguments; return
jQuery.Deferred(function( newDefer ) { jQuery.each( tuples,
function( i, tuple ) { var action = tuple[ 0 ], fn = jQuery.isFunction(
fns[ i ] ) && fns[ i ]; // deferred[ done | fail | progress ] for
forwarding actions to newDefer deferred[ tuple[1] ](function() { var
returned = fn && fn.apply( this, arguments ); if ( returned &&
jQuery.isFunction( returned.promise ) ) { returned.promise() .done(
newDefer.resolve ) .fail( newDefer.reject ) .progress(
newDefer.notify ); } else { newDefer[ action + "With" ]( this ===
promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
} }); }); fns = null; }).promise(); },
2013 © Trivadis
Focus
18.07.2013
JEE to the Max
6
Java
2013 © Trivadis
Server Sent Events
18.07.2013
JEE to the Max
7
2013 © Trivadis
Server Sent Events - Overview
• push from server to client
• SSE EventSource API part
of HTML5
• Part of Jersey 2 API’s (JAX-RS)
• JMS – Topic(Light)?
18.07.2013
JEE to the Max
8
2013 © Trivadis
SSE
DEMO
https://bitbucket.org/amoncsek/jeemax
18.07.2013
JEE to the Max
9
2013 © Trivadis
SSE
18.07.2013
JEE to the Max
10
TimerBean:
write(new Event(«custom»,data));
Handle:
void onEvent(InboundEvent e)
@Path(«myEventStream»)
Subscibe once:
new EventSource(http://.../myEventStream)
2013 © Trivadis
SSE- ServerSide
• Subscribe an Event Stream
@GET
@Produces(SseFeature.SERVER_SENT_EVENTS)
public EventOutput getEventStream() {
return new EventOutput();
}
• Put Message to EventOutput
EventOutput.write(
new OutboundEvent("custom-message“, message))
18.07.2013
JEE to the Max
11
2013 © Trivadis
SSE– ClientSide (Jersey 2 API’s)
• Client API
Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target(TARGET_URI);
• EventSource API
new EventSource(webTarget) {
public void onEvent(InboundEvent event) {…}
}
18.07.2013
JEE to the Max
12
2013 © Trivadis
SSE– Best Practice
• Client: EventSource.close() also closes the Server: EventOutput!
• Use SseBroadcaster to broadcast messages to EventOutput
• Register: SseBroadcaster.add(EventOutput)
• Broadcast: SseBroadcaster.broadcast(OutboundEvent)
• Use Server: OutboundEvent.name(«myMessage») to filter
messages (like JMS message-property/selector)
• Client: InboundEvent.getName().equals(«myMessage»)
18.07.2013
JEE to the Max
13
2013 © Trivadis
SSE
Any questions?
18.07.2013
JEE to the Max
14
2013 © Trivadis
WebSocket (JSR-356)
18.07.2013
JEE to the Max
15
2013 © Trivadis
WebSocket - Overview
18.07.2013
JEE to the Max
16
• Full duplex communication in either
direction
• Java API for Server- and Client-Side
(JEE7)
• Programmatic and annotation-based
endpoints
• Support for Encoder/Decoder to map
message to Java objects
• Support for @PathParam
2013 © Trivadis
WebSocket(JSR 356) - Overview
18.07.2013
JEE to the Max
17
• Part of Glassfish 4
• Tyrus project:
• reference implementation for JSR 356 WebSocket API for Java
• http://java.net/projects/tyrus
2013 © Trivadis
WebSocket
18.07.2013
JEE to the Max
18
@ServerEndpoint("/bookings") @ClientEndpoint
Session Session
messages
Connect
2013 © Trivadis
WebSocket – ServerEndpoint (by annotation)
18.07.2013
JEE to the Max
19
• Creating Server Endpoints with annotation
@ServerEndpoint("/bookings")
public class BookingEndpoint {
@OnOpen
public void init(Session s) {}
@OnClose
…
@OnError
…
@OnMessage
public void handleMessage(Message m, Session s) {}
}
2013 © Trivadis
WebSocket – ServerEndpoint (programmatic)
18.07.2013
JEE to the Max
20
• Creating Server Endpoints programmatic
public class BookingEndpoint extends Endpoint {
@Override
public void onOpen(Session s, EndpointConfig ec) {
s.addMessageHandler(new MessageHandler() {
@Override
public void onMessage(String text) {…}
});
}
}
2013 © Trivadis
WebSocket - ServerEndpoint
18.07.2013
JEE to the Max
21
• Configuring a programmatic Endpoint (WebSocket runtime scans the
WAR)
public class WSAppConfig implements ServerApplicationConfig
{
public Set<ServerEndpointConfig> getEndpointConfigs(Set
set) {
add(ServerEndpointConfig.Builder
.create(BookingEndpoint.class, "/bookings")
.build());
}
}
2013 © Trivadis
WebSocket - ClientEndpoint
18.07.2013
JEE to the Max
22
• Creating Client Endpoints with annotation
@ClientEndpoint
public class Booking {
@OnOpen
…
@OnClose
…
@OnError
…
@OnMessage
…
}
2013 © Trivadis
WebSocket - ClientEndpoint
18.07.2013
JEE to the Max
• Creating programmatic Client Endpoint
public class Booking extends Endpoint {
@Override
public void onOpen(Session s, EndpointConfig c) {
s.addMessageHandler(…);
}
}
23
2013 © Trivadis
WebSocket - ClientEndpoint
18.07.2013
JEE to the Max
24
• Configure a Client Endpoint
ClientManager client = ClientManager.createClient();
ClientEndpointConfig config =
ClientEndpointConfig.Builder.create();
client.connectToServer(new Booking(),config
URI.create(“ws://host/bookings“));
Or
client.connectToServer(Booking.class,config
URI.create(“ws://host/bookings“));
2013 © Trivadis
WebSocket Encoder/Decoder
• Native Message-format is:
• Text
• Binary
• Pong (check connection)
• Encoders:
• Encode message from Java Object to Binary / Text
• Decoders
• Decode message from Binary / Text to Java Object
18.07.2013
JEE to the Max
25
2013 © Trivadis
WebSocket Encoder
public class MEnc implements Encoder.Binary<Message> {
@Override
public ByteBuffer encode(Message m) throws EncodeException {
return ByteBuffer.wrap(SerializationUtils.serialize(message));
}
}
Register Encoders
Client: @ClientEndpoint(encoders = {Menc.class, Menc2.class})
Server: @ServerEndpoint(encoders = {Menc.class, Menc2.class})
18.07.2013
JEE to the Max
26
2013 © Trivadis
WebSocket Decoder
public class MessageDecoder implements Decoder.Binary<Message> {
public Message decode(ByteBuffer b) throws DecodeException {
return (Message) SerializationUtils.deserialize(b.array()); }
public boolean willDecode(ByteBuffer b) {
return true }
}
Register Decoders
Client: @ClientEndpoint(decoders = {MessageDecoder.class, Dec.class})
Server: @ServerEndpoint(decoders = {MessageDecoder.class, Dec.class})
18.07.2013
JEE to the Max
27
2013 © Trivadis
WebSocket @PathParam
• Annotate one or more parameters on:
• @OnMessage, @OnError, @OnClose, @OnOpen
@ServerEndpoint("/bookings/{id}")
public class BookingEndpoint {
@OnMessage
public void handle(@PathParam(“id”) String id,
Message m, Session s) {}
}
18.07.2013
JEE to the Max
28
2013 © Trivadis
WebSockets – sending messages
• BUT… how to send messages?
• BasicRemote: blocking until message has been transmitted
• session.getBasicRemote().sendObject(message);
• AsyncRemote: fire and forget
• Future<Void> v =
session.getAsyncRemote().sendObject(message);
• Progress may be tracked using the Future Object
18.07.2013
JEE to the Max
29
2013 © Trivadis
WebSockets – Broadcasting messages
• interaction with other Sessions
• Identify Sessions by ID
• Only Sessions in same Endpoint are accessible
• Sessions only accessible trough Session:
• session.getOpenSessions()
18.07.2013
JEE to the Max
30
2013 © Trivadis
Best Practice
• No automatic reconnection:
• Use OnError to reconnect
• Use Session.getUserProperties() to store additional informations
• Server Endpoitns have full support for CDI and @Inject
• Endpoint can be @Singleton / @Stateless… but requirement was
removed from spec!
18.07.2013
JEE to the Max
31
2013 © Trivadis
Best Practice
• One handling method per type!:
• Each websocket endpoint may only have one message handling
method for each of the native websocket message formats.
• Solution: inherence, Enums,…
18.07.2013
JEE to the Max
32
@OnMessage
public void onAddUser(AddUser user) {
}
@OnMessage
public void onMessage(Message m) {
}
@OnMessage
public void onChatMessage(Message chatMessage) {
switch (chatMessage.getType()){
case MESSAGE:
break;
case ADD_USER:
break;
}
}
2013 © Trivadis
WebSockets
Any questions?
18.07.2013
JEE to the Max
33
2013 © Trivadis
SSE / WebSockets in Enterprise
SSE / WebSockets in Enterprise
Securtity
18.07.2013
JEE to the Max
34
2013 © Trivadis
Security – Jersey 2 SSE
• Basic authentication - Jersey 2 way:
Client client = ClientBuilder.newBuilder().build();
WebTarget webTarget = client.target(restURL);
webTarget.register(new HttpBasicAuthFilter(user, pwd));
• Easy SSL konfigurations
SslConfigurator sslConfig =
SslConfigurator.newInstance()
.keyStoreFile("keystore.jks")
.keyPassword("asdfgh")
.scurityProtocol("SSL");
18.07.2013
JEE to the Max
35
2013 © Trivadis
Security – WebSocket (Tyrus API)
• Initial handshake over HTTP/HTTPS (ws:// | wss://)
• Session.getPrincipal() available
BUT….
NO Client API for authentication!
18.07.2013
JEE to the Max
36
2013 © Trivadis
Security – WebSocket (Tyrus API)
• Authentication is nevertheless possible (request properties)
c = new ClientEndpointConfig.Configurator() {
public void beforeRequest(Map<String, List<String>> headers)
{
headers.put("Authorization",
Arrays.asList("Basic " + BASE64Enc.encode(encPwd))));
}
};
config = ClientEndpointConfig.Builder.
create().
configurator(c).build();
client.connectToServer(CEndpoint.class, config, “ws://…/endpoint");
18.07.2013
JEE to the Max
37
2013 © Trivadis
Loadbalancing
18.07.2013
JEE to the Max
38
Loadbalancing
2013 © Trivadis
Loadbalancing - SSE
• Works with mod_proxy / mod_jk
• Problem: notification of EventOutput on each Cluster-Node (Broadcast)
• Workaround: bypass the LB and notify the nodes
• Duplicate messages to other nodes
• Use JMS to notify all nodes in cluster
18.07.2013
JEE to the Max
39
2013 © Trivadis
BASEL BERN LAUSANNE ZÜRICH DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MÜNCHEN STUTTGART WIEN
18.07.2013
JEE to the Max
‹#›
2013 © Trivadis
Failover
18.07.2013
JEE to the Max
41
Failover
2013 © Trivadis
Failover SSE
• On connection drop:
• Error event
• Try to reconnect
• default wait before trying to reconnect is 3 seconds
18.07.2013
JEE to the Max
42
2013 © Trivadis
Failover WebSockets
• No Session replication available in current (Tyrus) version!
• Use @OnError to reconnect on failure
• Do NOT use properties on Session
• Problem: message broadcasting
• Set LB weight 100 to one Node
• Ensure that all sessions on one Node
• Duplicate messages to other nodes
18.07.2013
JEE to the Max
43
2013 © Trivadis
SSE vs. WebSockets
• send/receive data from client
• provide true real-time
updates
• require servers that
understand the protocol
• Can identify peers (by ID)
18.07.2013
JEE to the Max
44
• push data to client
• can be configured to provide
close to real-time
• sent over traditional HTTP, so
no modification is required
• Can identify events (by ID)
WebSocket Server-Sent Events
2013 © Trivadis
Conclusion
Is it Enterprise Ready?
SSE – Yes
WebSocket - Nearly
18.07.2013
JEE to the Max
45
2013 © Trivadis
JEE 7 project overview
18.07.2013
JEE to the Max
46
• Client API - using builder pattern
• asynchronous request processing
Future<String> future =
client.target("http://...").pathParam("", "")
.request("text/plain").async().get(..);
[4]
2013 © Trivadis
JEE 7 project overview
18.07.2013
JEE to the Max
47
Example project with MongoDB
replication in Bitbucket (see Demos)
[4]
2013 © Trivadis
JEE 7 project overview
18.07.2013
JEE to the Max
48
@Resource(lookup = "jms/connectionFactory")
ConnectionFactory connectionFactory;
@Resource(lookup="jms/inboundQueue")
Queue inboundQueue;
public void sendMessageNew (String payload) {
try (JMSContext context = connectionFactory.createContext();)
{
context.send(inboundQueue,payload);
}
}
[4]
2013 © Trivadis
JEE 7 project overview
18.07.2013
JEE to the Max
49
@Resource(name = "concurrent/myExecutor")
ManagedExecutorService executor;
executor.execute(new MyRunnableTask(2));
[4]
2013 © Trivadis
BASEL BERN LAUSANNE ZÜRICH DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MÜNCHEN STUTTGART WIEN
VIELEN DANK.
Andy Moncsek
Andy.Moncsek@Trivadis.com
www.trivadis.com
18.07.2013
JEE to the Max
50
2013 © Trivadis
Appendix
1. Wallpaper: http://bensow.deviantart.com/art/Wallpaper-Under-Construction-
252593627
2. http://de.slideshare.net/MasoudKalali/server-sent-events-async-servlet-web-
sockets-and-json-born-to-work-together
3. Tyrus Project: http://java.net/projects/tyrus
4. Jersey 2: http://jersey.java.net/jersey20.html
5. JacpFX: https://code.google.com/p/jacp/
6. GlassFish 4 downloads: http://glassfish.java.net/public/downloadsindex.html
7. [3] http://blog.exceliance.fr/2012/11/07/websockets-load-balancing-with-
haproxy/
8. [4] http://de.slideshare.net/arungupta1/the-java-ee-7-platform-productivity-
html5-16124993
9. http://download.oracle.com/otndocs/jcp/websocket-1_0-pfd-spec/index.html
18.07.2013
JEE to the Max
51

Contenu connexe

Similaire à Scalableenterpriseapplicationswith jee7andbeyond

JavaFX / JacpFX interaction with JSR356 WebSockets
JavaFX / JacpFX interaction with JSR356 WebSocketsJavaFX / JacpFX interaction with JSR356 WebSockets
JavaFX / JacpFX interaction with JSR356 WebSocketsAndy Moncsek
 
Java springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology MeetupJava springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology MeetupAccenture Hungary
 
Front end microservices - October 2019
Front end microservices - October 2019Front end microservices - October 2019
Front end microservices - October 2019Mikhail Kuznetcov
 
Silverlight 4 @ MSDN Live
Silverlight 4 @ MSDN LiveSilverlight 4 @ MSDN Live
Silverlight 4 @ MSDN Livegoeran
 
From Zero to Cloud in 12 Easy Factors
From Zero to Cloud in 12 Easy FactorsFrom Zero to Cloud in 12 Easy Factors
From Zero to Cloud in 12 Easy FactorsEd King
 
Inter-Sling communication with message queue
Inter-Sling communication with message queueInter-Sling communication with message queue
Inter-Sling communication with message queueTomasz Rękawek
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developerEdureka!
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperEdureka!
 
7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script TaskPramod Singla
 
Creating a Java Internet of Things Gateway
Creating a Java Internet of Things GatewayCreating a Java Internet of Things Gateway
Creating a Java Internet of Things GatewayEurotech
 
NodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayNodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayEdureka!
 
Microservices with Node.js and Apache Cassandra
Microservices with Node.js and Apache CassandraMicroservices with Node.js and Apache Cassandra
Microservices with Node.js and Apache CassandraJorge Bay Gondra
 
Session 3: Windows Azure Platform as a Service (PaaS)
Session 3: Windows Azure Platform as a Service (PaaS)Session 3: Windows Azure Platform as a Service (PaaS)
Session 3: Windows Azure Platform as a Service (PaaS)Digicomp Academy AG
 
Android training in mumbai
Android training in mumbaiAndroid training in mumbai
Android training in mumbaiCIBIL
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup PerformanceGreg Whalin
 
Composition and Execution of Secure Workflows in WSRF-Grids, IEEE CCGrid 2008...
Composition and Execution of Secure Workflows in WSRF-Grids, IEEE CCGrid 2008...Composition and Execution of Secure Workflows in WSRF-Grids, IEEE CCGrid 2008...
Composition and Execution of Secure Workflows in WSRF-Grids, IEEE CCGrid 2008...Dr. Tim Dörnemann
 
How to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita GalkinHow to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita GalkinSigma Software
 
Timings API: Performance Assertion during the functional testing
 Timings API: Performance Assertion during the functional testing Timings API: Performance Assertion during the functional testing
Timings API: Performance Assertion during the functional testingPetrosPlakogiannis
 

Similaire à Scalableenterpriseapplicationswith jee7andbeyond (20)

JavaFX / JacpFX interaction with JSR356 WebSockets
JavaFX / JacpFX interaction with JSR356 WebSocketsJavaFX / JacpFX interaction with JSR356 WebSockets
JavaFX / JacpFX interaction with JSR356 WebSockets
 
Java springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology MeetupJava springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology Meetup
 
Front end microservices - October 2019
Front end microservices - October 2019Front end microservices - October 2019
Front end microservices - October 2019
 
Silverlight 4 @ MSDN Live
Silverlight 4 @ MSDN LiveSilverlight 4 @ MSDN Live
Silverlight 4 @ MSDN Live
 
From Zero to Cloud in 12 Easy Factors
From Zero to Cloud in 12 Easy FactorsFrom Zero to Cloud in 12 Easy Factors
From Zero to Cloud in 12 Easy Factors
 
Inter-Sling communication with message queue
Inter-Sling communication with message queueInter-Sling communication with message queue
Inter-Sling communication with message queue
 
Android - Api & Debugging in Android
Android - Api & Debugging in AndroidAndroid - Api & Debugging in Android
Android - Api & Debugging in Android
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 
7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task
 
Creating a Java Internet of Things Gateway
Creating a Java Internet of Things GatewayCreating a Java Internet of Things Gateway
Creating a Java Internet of Things Gateway
 
NodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin WayNodeJS : Communication and Round Robin Way
NodeJS : Communication and Round Robin Way
 
Microservices with Node.js and Apache Cassandra
Microservices with Node.js and Apache CassandraMicroservices with Node.js and Apache Cassandra
Microservices with Node.js and Apache Cassandra
 
Session 3: Windows Azure Platform as a Service (PaaS)
Session 3: Windows Azure Platform as a Service (PaaS)Session 3: Windows Azure Platform as a Service (PaaS)
Session 3: Windows Azure Platform as a Service (PaaS)
 
Android training in mumbai
Android training in mumbaiAndroid training in mumbai
Android training in mumbai
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Composition and Execution of Secure Workflows in WSRF-Grids, IEEE CCGrid 2008...
Composition and Execution of Secure Workflows in WSRF-Grids, IEEE CCGrid 2008...Composition and Execution of Secure Workflows in WSRF-Grids, IEEE CCGrid 2008...
Composition and Execution of Secure Workflows in WSRF-Grids, IEEE CCGrid 2008...
 
How to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita GalkinHow to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita Galkin
 
Timings API: Performance Assertion during the functional testing
 Timings API: Performance Assertion during the functional testing Timings API: Performance Assertion during the functional testing
Timings API: Performance Assertion during the functional testing
 

Plus de Andy Moncsek

The JVM in the Cloud: OpenJ9 and the traditional HotSpot JVM
The JVM in the Cloud: OpenJ9 and the traditional HotSpot JVMThe JVM in the Cloud: OpenJ9 and the traditional HotSpot JVM
The JVM in the Cloud: OpenJ9 and the traditional HotSpot JVMAndy Moncsek
 
Master your java_applications_in_kubernetes
Master your java_applications_in_kubernetesMaster your java_applications_in_kubernetes
Master your java_applications_in_kubernetesAndy Moncsek
 
Going serverless with Fn project, Fn Flow and Kubernetes
Going serverless with Fn project, Fn Flow and KubernetesGoing serverless with Fn project, Fn Flow and Kubernetes
Going serverless with Fn project, Fn Flow and KubernetesAndy Moncsek
 
Vert.x based microservices with vxms
Vert.x based microservices with vxmsVert.x based microservices with vxms
Vert.x based microservices with vxmsAndy Moncsek
 
Event driven microservices with vxms, hazelcast and kubernetes - muenchen
Event driven microservices with vxms, hazelcast and kubernetes - muenchenEvent driven microservices with vxms, hazelcast and kubernetes - muenchen
Event driven microservices with vxms, hazelcast and kubernetes - muenchenAndy Moncsek
 
Event driven microservices with vertx and kubernetes
Event driven microservices with vertx and kubernetesEvent driven microservices with vertx and kubernetes
Event driven microservices with vertx and kubernetesAndy Moncsek
 
autodiscoverable microservices with vertx3
autodiscoverable microservices with vertx3autodiscoverable microservices with vertx3
autodiscoverable microservices with vertx3Andy Moncsek
 
Building non-blocking JavaFX 8 applications with JacpFX [CON1823]
Building non-blocking JavaFX 8 applications with JacpFX [CON1823]Building non-blocking JavaFX 8 applications with JacpFX [CON1823]
Building non-blocking JavaFX 8 applications with JacpFX [CON1823]Andy Moncsek
 

Plus de Andy Moncsek (8)

The JVM in the Cloud: OpenJ9 and the traditional HotSpot JVM
The JVM in the Cloud: OpenJ9 and the traditional HotSpot JVMThe JVM in the Cloud: OpenJ9 and the traditional HotSpot JVM
The JVM in the Cloud: OpenJ9 and the traditional HotSpot JVM
 
Master your java_applications_in_kubernetes
Master your java_applications_in_kubernetesMaster your java_applications_in_kubernetes
Master your java_applications_in_kubernetes
 
Going serverless with Fn project, Fn Flow and Kubernetes
Going serverless with Fn project, Fn Flow and KubernetesGoing serverless with Fn project, Fn Flow and Kubernetes
Going serverless with Fn project, Fn Flow and Kubernetes
 
Vert.x based microservices with vxms
Vert.x based microservices with vxmsVert.x based microservices with vxms
Vert.x based microservices with vxms
 
Event driven microservices with vxms, hazelcast and kubernetes - muenchen
Event driven microservices with vxms, hazelcast and kubernetes - muenchenEvent driven microservices with vxms, hazelcast and kubernetes - muenchen
Event driven microservices with vxms, hazelcast and kubernetes - muenchen
 
Event driven microservices with vertx and kubernetes
Event driven microservices with vertx and kubernetesEvent driven microservices with vertx and kubernetes
Event driven microservices with vertx and kubernetes
 
autodiscoverable microservices with vertx3
autodiscoverable microservices with vertx3autodiscoverable microservices with vertx3
autodiscoverable microservices with vertx3
 
Building non-blocking JavaFX 8 applications with JacpFX [CON1823]
Building non-blocking JavaFX 8 applications with JacpFX [CON1823]Building non-blocking JavaFX 8 applications with JacpFX [CON1823]
Building non-blocking JavaFX 8 applications with JacpFX [CON1823]
 

Dernier

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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 

Dernier (20)

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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Scalableenterpriseapplicationswith jee7andbeyond

  • 1. 2013 © Trivadis BASEL BERN LAUSANNE ZÜRICH DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MÜNCHEN STUTTGART WIEN JUG Münster Scalable enterprise applications with JEE7 and beyond Andy Moncsek 17. April 2013 18.07.2013 JEE to the Max 1
  • 2. 2013 © Trivadis BASEL BERN LAUSANNE ZÜRICH DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MÜNCHEN STUTTGART WIEN Andy Moncsek Consultant for Application Devlopment (Zürich) Trainer for JavaEE Assembly & Deployment Contacts: Andy.Moncsek@Trivadis.com Twitter: @AndyAHCP
  • 3. 2013 © Trivadis AGENDA 1. Motivation 2. Server Sent Events 3. WebSocket (JSR-356) 4. SSE & WebSockets in Enterprise  Security  Loadbalancing / Failover 5. (short) JEE 7 project overview 18.07.2013 JEE to the Max 3
  • 4. 2013 © Trivadis Motivation 18.07.2013 JEE to the Max 4 JEE 7 what’s new?
  • 5. 2013 © Trivadis Motivation 18.07.2013 JEE to the Max 5 state: function() { return state; }, always: function() { deferred.done( arguments ).fail( arguments ); return this; }, then: function( /* fnDone, fnFail, fnProgress */ ) { var fns = arguments; return jQuery.Deferred(function( newDefer ) { jQuery.each( tuples, function( i, tuple ) { var action = tuple[ 0 ], fn = jQuery.isFunction( fns[ i ] ) && fns[ i ]; // deferred[ done | fail | progress ] for forwarding actions to newDefer deferred[ tuple[1] ](function() { var returned = fn && fn.apply( this, arguments ); if ( returned && jQuery.isFunction( returned.promise ) ) { returned.promise() .done( newDefer.resolve ) .fail( newDefer.reject ) .progress( newDefer.notify ); } else { newDefer[ action + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments ); } }); }); fns = null; }).promise(); },
  • 7. 2013 © Trivadis Server Sent Events 18.07.2013 JEE to the Max 7
  • 8. 2013 © Trivadis Server Sent Events - Overview • push from server to client • SSE EventSource API part of HTML5 • Part of Jersey 2 API’s (JAX-RS) • JMS – Topic(Light)? 18.07.2013 JEE to the Max 8
  • 10. 2013 © Trivadis SSE 18.07.2013 JEE to the Max 10 TimerBean: write(new Event(«custom»,data)); Handle: void onEvent(InboundEvent e) @Path(«myEventStream») Subscibe once: new EventSource(http://.../myEventStream)
  • 11. 2013 © Trivadis SSE- ServerSide • Subscribe an Event Stream @GET @Produces(SseFeature.SERVER_SENT_EVENTS) public EventOutput getEventStream() { return new EventOutput(); } • Put Message to EventOutput EventOutput.write( new OutboundEvent("custom-message“, message)) 18.07.2013 JEE to the Max 11
  • 12. 2013 © Trivadis SSE– ClientSide (Jersey 2 API’s) • Client API Client client = ClientBuilder.newClient(); WebTarget webTarget = client.target(TARGET_URI); • EventSource API new EventSource(webTarget) { public void onEvent(InboundEvent event) {…} } 18.07.2013 JEE to the Max 12
  • 13. 2013 © Trivadis SSE– Best Practice • Client: EventSource.close() also closes the Server: EventOutput! • Use SseBroadcaster to broadcast messages to EventOutput • Register: SseBroadcaster.add(EventOutput) • Broadcast: SseBroadcaster.broadcast(OutboundEvent) • Use Server: OutboundEvent.name(«myMessage») to filter messages (like JMS message-property/selector) • Client: InboundEvent.getName().equals(«myMessage») 18.07.2013 JEE to the Max 13
  • 14. 2013 © Trivadis SSE Any questions? 18.07.2013 JEE to the Max 14
  • 15. 2013 © Trivadis WebSocket (JSR-356) 18.07.2013 JEE to the Max 15
  • 16. 2013 © Trivadis WebSocket - Overview 18.07.2013 JEE to the Max 16 • Full duplex communication in either direction • Java API for Server- and Client-Side (JEE7) • Programmatic and annotation-based endpoints • Support for Encoder/Decoder to map message to Java objects • Support for @PathParam
  • 17. 2013 © Trivadis WebSocket(JSR 356) - Overview 18.07.2013 JEE to the Max 17 • Part of Glassfish 4 • Tyrus project: • reference implementation for JSR 356 WebSocket API for Java • http://java.net/projects/tyrus
  • 18. 2013 © Trivadis WebSocket 18.07.2013 JEE to the Max 18 @ServerEndpoint("/bookings") @ClientEndpoint Session Session messages Connect
  • 19. 2013 © Trivadis WebSocket – ServerEndpoint (by annotation) 18.07.2013 JEE to the Max 19 • Creating Server Endpoints with annotation @ServerEndpoint("/bookings") public class BookingEndpoint { @OnOpen public void init(Session s) {} @OnClose … @OnError … @OnMessage public void handleMessage(Message m, Session s) {} }
  • 20. 2013 © Trivadis WebSocket – ServerEndpoint (programmatic) 18.07.2013 JEE to the Max 20 • Creating Server Endpoints programmatic public class BookingEndpoint extends Endpoint { @Override public void onOpen(Session s, EndpointConfig ec) { s.addMessageHandler(new MessageHandler() { @Override public void onMessage(String text) {…} }); } }
  • 21. 2013 © Trivadis WebSocket - ServerEndpoint 18.07.2013 JEE to the Max 21 • Configuring a programmatic Endpoint (WebSocket runtime scans the WAR) public class WSAppConfig implements ServerApplicationConfig { public Set<ServerEndpointConfig> getEndpointConfigs(Set set) { add(ServerEndpointConfig.Builder .create(BookingEndpoint.class, "/bookings") .build()); } }
  • 22. 2013 © Trivadis WebSocket - ClientEndpoint 18.07.2013 JEE to the Max 22 • Creating Client Endpoints with annotation @ClientEndpoint public class Booking { @OnOpen … @OnClose … @OnError … @OnMessage … }
  • 23. 2013 © Trivadis WebSocket - ClientEndpoint 18.07.2013 JEE to the Max • Creating programmatic Client Endpoint public class Booking extends Endpoint { @Override public void onOpen(Session s, EndpointConfig c) { s.addMessageHandler(…); } } 23
  • 24. 2013 © Trivadis WebSocket - ClientEndpoint 18.07.2013 JEE to the Max 24 • Configure a Client Endpoint ClientManager client = ClientManager.createClient(); ClientEndpointConfig config = ClientEndpointConfig.Builder.create(); client.connectToServer(new Booking(),config URI.create(“ws://host/bookings“)); Or client.connectToServer(Booking.class,config URI.create(“ws://host/bookings“));
  • 25. 2013 © Trivadis WebSocket Encoder/Decoder • Native Message-format is: • Text • Binary • Pong (check connection) • Encoders: • Encode message from Java Object to Binary / Text • Decoders • Decode message from Binary / Text to Java Object 18.07.2013 JEE to the Max 25
  • 26. 2013 © Trivadis WebSocket Encoder public class MEnc implements Encoder.Binary<Message> { @Override public ByteBuffer encode(Message m) throws EncodeException { return ByteBuffer.wrap(SerializationUtils.serialize(message)); } } Register Encoders Client: @ClientEndpoint(encoders = {Menc.class, Menc2.class}) Server: @ServerEndpoint(encoders = {Menc.class, Menc2.class}) 18.07.2013 JEE to the Max 26
  • 27. 2013 © Trivadis WebSocket Decoder public class MessageDecoder implements Decoder.Binary<Message> { public Message decode(ByteBuffer b) throws DecodeException { return (Message) SerializationUtils.deserialize(b.array()); } public boolean willDecode(ByteBuffer b) { return true } } Register Decoders Client: @ClientEndpoint(decoders = {MessageDecoder.class, Dec.class}) Server: @ServerEndpoint(decoders = {MessageDecoder.class, Dec.class}) 18.07.2013 JEE to the Max 27
  • 28. 2013 © Trivadis WebSocket @PathParam • Annotate one or more parameters on: • @OnMessage, @OnError, @OnClose, @OnOpen @ServerEndpoint("/bookings/{id}") public class BookingEndpoint { @OnMessage public void handle(@PathParam(“id”) String id, Message m, Session s) {} } 18.07.2013 JEE to the Max 28
  • 29. 2013 © Trivadis WebSockets – sending messages • BUT… how to send messages? • BasicRemote: blocking until message has been transmitted • session.getBasicRemote().sendObject(message); • AsyncRemote: fire and forget • Future<Void> v = session.getAsyncRemote().sendObject(message); • Progress may be tracked using the Future Object 18.07.2013 JEE to the Max 29
  • 30. 2013 © Trivadis WebSockets – Broadcasting messages • interaction with other Sessions • Identify Sessions by ID • Only Sessions in same Endpoint are accessible • Sessions only accessible trough Session: • session.getOpenSessions() 18.07.2013 JEE to the Max 30
  • 31. 2013 © Trivadis Best Practice • No automatic reconnection: • Use OnError to reconnect • Use Session.getUserProperties() to store additional informations • Server Endpoitns have full support for CDI and @Inject • Endpoint can be @Singleton / @Stateless… but requirement was removed from spec! 18.07.2013 JEE to the Max 31
  • 32. 2013 © Trivadis Best Practice • One handling method per type!: • Each websocket endpoint may only have one message handling method for each of the native websocket message formats. • Solution: inherence, Enums,… 18.07.2013 JEE to the Max 32 @OnMessage public void onAddUser(AddUser user) { } @OnMessage public void onMessage(Message m) { } @OnMessage public void onChatMessage(Message chatMessage) { switch (chatMessage.getType()){ case MESSAGE: break; case ADD_USER: break; } }
  • 33. 2013 © Trivadis WebSockets Any questions? 18.07.2013 JEE to the Max 33
  • 34. 2013 © Trivadis SSE / WebSockets in Enterprise SSE / WebSockets in Enterprise Securtity 18.07.2013 JEE to the Max 34
  • 35. 2013 © Trivadis Security – Jersey 2 SSE • Basic authentication - Jersey 2 way: Client client = ClientBuilder.newBuilder().build(); WebTarget webTarget = client.target(restURL); webTarget.register(new HttpBasicAuthFilter(user, pwd)); • Easy SSL konfigurations SslConfigurator sslConfig = SslConfigurator.newInstance() .keyStoreFile("keystore.jks") .keyPassword("asdfgh") .scurityProtocol("SSL"); 18.07.2013 JEE to the Max 35
  • 36. 2013 © Trivadis Security – WebSocket (Tyrus API) • Initial handshake over HTTP/HTTPS (ws:// | wss://) • Session.getPrincipal() available BUT…. NO Client API for authentication! 18.07.2013 JEE to the Max 36
  • 37. 2013 © Trivadis Security – WebSocket (Tyrus API) • Authentication is nevertheless possible (request properties) c = new ClientEndpointConfig.Configurator() { public void beforeRequest(Map<String, List<String>> headers) { headers.put("Authorization", Arrays.asList("Basic " + BASE64Enc.encode(encPwd)))); } }; config = ClientEndpointConfig.Builder. create(). configurator(c).build(); client.connectToServer(CEndpoint.class, config, “ws://…/endpoint"); 18.07.2013 JEE to the Max 37
  • 38. 2013 © Trivadis Loadbalancing 18.07.2013 JEE to the Max 38 Loadbalancing
  • 39. 2013 © Trivadis Loadbalancing - SSE • Works with mod_proxy / mod_jk • Problem: notification of EventOutput on each Cluster-Node (Broadcast) • Workaround: bypass the LB and notify the nodes • Duplicate messages to other nodes • Use JMS to notify all nodes in cluster 18.07.2013 JEE to the Max 39
  • 40. 2013 © Trivadis BASEL BERN LAUSANNE ZÜRICH DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MÜNCHEN STUTTGART WIEN 18.07.2013 JEE to the Max ‹#›
  • 42. 2013 © Trivadis Failover SSE • On connection drop: • Error event • Try to reconnect • default wait before trying to reconnect is 3 seconds 18.07.2013 JEE to the Max 42
  • 43. 2013 © Trivadis Failover WebSockets • No Session replication available in current (Tyrus) version! • Use @OnError to reconnect on failure • Do NOT use properties on Session • Problem: message broadcasting • Set LB weight 100 to one Node • Ensure that all sessions on one Node • Duplicate messages to other nodes 18.07.2013 JEE to the Max 43
  • 44. 2013 © Trivadis SSE vs. WebSockets • send/receive data from client • provide true real-time updates • require servers that understand the protocol • Can identify peers (by ID) 18.07.2013 JEE to the Max 44 • push data to client • can be configured to provide close to real-time • sent over traditional HTTP, so no modification is required • Can identify events (by ID) WebSocket Server-Sent Events
  • 45. 2013 © Trivadis Conclusion Is it Enterprise Ready? SSE – Yes WebSocket - Nearly 18.07.2013 JEE to the Max 45
  • 46. 2013 © Trivadis JEE 7 project overview 18.07.2013 JEE to the Max 46 • Client API - using builder pattern • asynchronous request processing Future<String> future = client.target("http://...").pathParam("", "") .request("text/plain").async().get(..); [4]
  • 47. 2013 © Trivadis JEE 7 project overview 18.07.2013 JEE to the Max 47 Example project with MongoDB replication in Bitbucket (see Demos) [4]
  • 48. 2013 © Trivadis JEE 7 project overview 18.07.2013 JEE to the Max 48 @Resource(lookup = "jms/connectionFactory") ConnectionFactory connectionFactory; @Resource(lookup="jms/inboundQueue") Queue inboundQueue; public void sendMessageNew (String payload) { try (JMSContext context = connectionFactory.createContext();) { context.send(inboundQueue,payload); } } [4]
  • 49. 2013 © Trivadis JEE 7 project overview 18.07.2013 JEE to the Max 49 @Resource(name = "concurrent/myExecutor") ManagedExecutorService executor; executor.execute(new MyRunnableTask(2)); [4]
  • 50. 2013 © Trivadis BASEL BERN LAUSANNE ZÜRICH DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MÜNCHEN STUTTGART WIEN VIELEN DANK. Andy Moncsek Andy.Moncsek@Trivadis.com www.trivadis.com 18.07.2013 JEE to the Max 50
  • 51. 2013 © Trivadis Appendix 1. Wallpaper: http://bensow.deviantart.com/art/Wallpaper-Under-Construction- 252593627 2. http://de.slideshare.net/MasoudKalali/server-sent-events-async-servlet-web- sockets-and-json-born-to-work-together 3. Tyrus Project: http://java.net/projects/tyrus 4. Jersey 2: http://jersey.java.net/jersey20.html 5. JacpFX: https://code.google.com/p/jacp/ 6. GlassFish 4 downloads: http://glassfish.java.net/public/downloadsindex.html 7. [3] http://blog.exceliance.fr/2012/11/07/websockets-load-balancing-with- haproxy/ 8. [4] http://de.slideshare.net/arungupta1/the-java-ee-7-platform-productivity- html5-16124993 9. http://download.oracle.com/otndocs/jcp/websocket-1_0-pfd-spec/index.html 18.07.2013 JEE to the Max 51

Notes de l'éditeur

  1. Alle Beispiele und Tests mit GlassFish 4 promotionbuilds
  2. Einordnung: Technologien mit denen man Daten vom Server zum Client übeträgt; Longpolling GET…Wait,Wait… Work; GET; SSE nur initiales GET, WebSocket: nur Handshake über HTTP
  3. SSE keine eigeneSpz. Sondern in JAX-RS angesiedelt; Implementierung als Teil von Jersey 2
  4. Repo: JEE 7 maven Projekt mit aktuell 3 Subprojekten; SSE,WebSocket, NoSQL Demo; Ziel: bis zum final aktuell halten als Anlaufpunkt für JEE 7 / GlassFish Tests
  5. List items are corresponding to header declaration in HTTP request.public Map&lt;String, List&lt;String&gt;&gt; getHeaders() /** * Returns the header value corresponding to the name.public String getHeader(String name) { final List&lt;String&gt; stringList = headers.get(name); return stringList == null ? null : stringList.get(0); }
  6. Beispiel Backoffice Systeme: mehrer Nutzer bearbeiten einkommende Aufträge… mit beiden Techn. Möglich… neue Aufträge werden per broadcast an alle gesendet, bearbeiter sperrt Auftrag und beareitet ihn  statusänderung an alle