Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Spring MVC 4.2: New and Noteworthy

3,948 views

Published on

Recorded at SpringOne2GX 2015
Presenter: Rossen Stoyanchev
Web / Javascript Track
This talk provides a practical overview of new features for web applications in Spring Framework 4.2 including the addition of HTTP streaming, Server-Sent Events, a fine-grained model for cross-origin requests, comprehensive HTTP caching updates, and more. There are also plenty of updates for WebSocket-style messaging which this talk will cover.

Published in: Technology

Spring MVC 4.2: New and Noteworthy

  1. 1. SPRINGONE2GX WASHINGTON, DC Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring MVC 4.2: New and Noteworthy Rossen Stoyanchev
  2. 2. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ About Me • Spring Framework committer • Spring MVC • Spring WebSocket 2
  3. 3. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo Source 3 https://github.com/rstoyanchev/ s2gx2015-spring-mvc-42
  4. 4. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ HTTP Streaming 4
  5. 5. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring 3.2: Async Request Handling • The ability to get off the Servlet container thread • Take any controller method • replace return value T with DeferredResult<T> • Range of use cases • long polling -- chat, live events • processing with latency -- scatter-gather, microservices • Easy to introduce into existing apps 5
  6. 6. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring 4.0: WebSocket Messaging • Full duplex messaging with SockJS emulation • STOMP for application messaging • simple or external broker • @MessagingMapping methods for application work • More advanced messaging needs • collaboration, games • Very different from REST -- messaging architecture 6
  7. 7. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ • Return ResponseBodyEmitter rather than @ResponseBody • Or ResponseEntity<ResponseBodyEmitter> • Stream of serialized Objects, emitted from any thread • Objects serialized with HttpMessageConverter Spring 4.2: HTTP Streaming 7
  8. 8. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Example @RequestMapping(path = "/stream", method = GET) public ResponseBodyEmitter startStream() { ResponseBodyEmitter emitter = new ResponseBodyEmitter(); ... return emitter; } // Later on emitter.send(foo, MediaType.APPLICATION_JSON); ... emitter.send(bar, MediaType.APPLICATION_JSON); ... emitter.complete(); 8 MediaType used to select a converter
  9. 9. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ • Store ResponseBodyEmitter instances • in controller • in another component where events received • Use onCompletion callback (on emitter) to remove instance • Manual pub-sub to connected users • Compare to STOMP + WebSocket • messaging protocol with built-in pub-sub Pub-Sub 9
  10. 10. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ • Return SseEmitter, an extension of ResponseBodyEmitter • HTTP streaming with event markup Spring 4.2: Server-Sent Events 10
  11. 11. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Example @RequestMapping(path = "/stream", method = GET) public SseEmitter startStream() { SseEmitter emitter = new SseEmitter(); ... return emitter; } // Later on emitter.send(event().event().id("id").name("type").data(foo)); ... emitter.complete(); 11
  12. 12. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring 4.2: Direct Streaming • No serialization with HttpMessageConverter • Stream directly to the response • Return StreamingResponseBody instead of @ResponseBody • ResponseEntity<StreamingResponseBody> 12
  13. 13. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Example @RequestMapping(path = "/stream", method = GET) public StreamingResponseBody handle() { return new StreamingResponseBody() { @Override public void writeTo(OutputStream os) throws IOException { os.write(...); os.flush(); } }; } 13
  14. 14. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ HTTP Streaming vs WebSocket Messaging • HTTP Streaming / SSE -- suited for simple streaming needs • metrics, feeds • STOMP / WebSocket scales to more advanced needs • finance, collaboration, games • SockJS has lots of built-in smarts • fallback to polling if network/proxy prevents streaming • the extra mile for extra range of browsers 14
  15. 15. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ CORS 15
  16. 16. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ CORS Overview • Browsers prohibit requests to a different domain • e.g. evil.com → bank.com • CORS is a W3C specification for cross-domain requests • For “simple” methods (GET, HEAD, POST) • browser sets Origin header • Otherwise “preflight” request to obtain permission • HTTP OPTIONS • Origin and Access-Control-Request-Method headers 16
  17. 17. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ CORS Support in Spring? • Tomcat, Jetty, others provide CORS Filter implementations • First-class support within Spring however still beneficial • More fine-grained control (based on request mappings) • Layer central + local configuration 17
  18. 18. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Local Configuration for @Controller • New @CrossOrigin annotation • Supported on individual @RequestMapping methods • Inherited from the class level • Easy to configure one method or entire controller class hierarchy 18
  19. 19. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Local Configuration for Simple Handlers • Implement CorsConfigurationSource • Two built-in handlers that make use this contract • ResourceHttpRequestHandler • SockJsHttpRequestHandler public interface CorsConfigurationSource { CorsConfiguration getCorsConfiguration(HttpServletRequest req); } 19
  20. 20. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Central Configuration • The MVC Java config and MVC namespace expose CORS configuration • Centralized configuration alternative • URL patterns based • Layer central + local configuration • e.g. define general policy (e.g. allow csrf-token header) • refine locally 20
  21. 21. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ More on CORS Configuration • AbstractHandlerMapping drives overall CORS handling • It’s an internal feature that’s always on • cross-domain not allowed by default (as before) • DispatcherServlet allows preflight requests in for handling • no need to set dispatchOptionsRequest 21
  22. 22. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring MVC CORS and Spring Security • DispatcherServlet now provides CORS handling • Spring Security needs to open HTTP OPTIONS (for preflight requests) • There is work planned to improve this • only allow preflight requests with Spring MVC 22
  23. 23. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ CorsFilter • Filter-based approach to CORS configuration • Comparable to Tomcat, Jetty filters • CORS handling strictly before DispatcherServlet • CorsFilter can/should be ordered before Spring Security Filter chain 23
  24. 24. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ HTTP Caching 24
  25. 25. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Goals • Update default settings in line with current browsers/proxies • Improve options local to @MVC controllers • Provide use-case oriented + advanced config • Various other improvements • Cache-Control directives, eTag/LastModified support 25
  26. 26. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ CacheControl • Convenient “Cache-Control” response header value builder • Covers the common use cases • CacheControl.maxAge(...)# cache for... • CacheControl.noStore() # prevent cache • CacheControl.noCache() # conditional cache + eTag/lastModified • And the advanced • CacheControl.maxAge(...).noTransform().cachePublic() 26
  27. 27. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ WebContentGenerator • Central HTTP cache configuration class • WebContentInterceptor, ResourceHttpRequestHandler • Defaults settings revised • no more HTTP 1.0 headers (“Expires” and “Pragma”) • cacheSeconds shortcut relies CacheControl • Accepts CacheControl builder for its configuration • Plus existing cacheSeconds shortcut (becomes CacheControl) 27
  28. 28. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @MVC • ResponseEntity supports HTTP cache settings ResponseEntity.ok() .cacheControl(CacheControl.maxAge(30, TimeUnit.DAYS)) .eTag(version) // lastModified also available .body(book); • Sets response headers + checks client conditional headers • Sends 304 (“not modified”) if eTag matches 28
  29. 29. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @MVC Continued • Explicit eTag / lastModified checks also possible @RequestMapping public Object handle(WebRequest request) { long lastModified = ... if (request.checkNotModified(lastModified)) { return null; } // ... } • Possible to check both eTag + lastModified (per recommendation) • request.checkNotModified(eTag,lastModified) 29
  30. 30. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Resource Handling • Extended HTTP cache control for serving static resources • MVC Java config • ResourceHandlerRegistry accepts CacheControl • MVC XML namespace • <mvc:cache-control> element within <mvc:resources> • eTag added when VersionResourceResolver is configured 30
  31. 31. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Additional Reading • HTTP Caching Tutorial by Mark Nottingham • Reference documentation HTTP Caching Support • Notes in Migration from earlier versions wiki page 31
  32. 32. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Composable @RequestMapping 32
  33. 33. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Custom @RequestMapping • For example: @PostJson("/input") public Object handle() { return … ; } • Given custom annotation: @RequestMapping(method=GET, produces="application/json") public @interface PostJson { String value() default ""; } 33
  34. 34. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Shortcut Annotations? • Proposal to provide built-in shortcut annotations • The challenge is finding the right mix • Feedback based on specific use cases would help greatly • SPR-13442 and spring-composed project 34
  35. 35. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Jackson 35
  36. 36. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Selective Serialization with @JsonView • Supported on @RequestMapping methods (since 4.1) @RequestMapping @JsonView(SummaryView.class) public ResponseEntity<Foo> handle() { // … } • Now also with @RequestBody @RequestMapping (method = POST) public void handle(@JsonView(SummaryView.class) @RequestBody Foo foo) { // ... } 36
  37. 37. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Jackson Modules • Jackson2ObjectMapperBuilder auto-registers Jackson modules • jdk7, joda, jsr310, jdk8 • Conditional on classpath detection of target dependencies • Both MVC Java config and XML namespace use Jackson2ObjectMapperBuilder 37
  38. 38. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @MVC 38
  39. 39. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Programming Model • HandlerMethod argument for @ExceptionHandler methods • could be handy with @ControllerAdvice • CharSequence as controller method return value (alternative to String) • groovy.lang.GString, StringBuilder, StringBuffer • @InitBinder methods can register Formatter for specific field(s) • otherwise typically global in ConversionService 39
  40. 40. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Async Return Value Types • Built-in support for • org.springframework.util.concurrent.ListenableFuture (4.1) • java.util.concurrent.CompletionStage (4.2) • Both adapted to DeferredResult • Easy to adapt others • RxJava Observable, Reactor Stream, … • Follow example of built-in types 40
  41. 41. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JavaScript Templating 41
  42. 42. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Why? • Traditionally HTML served then enhanced with JavaScript • Trend towards generating the UI with JavaScript • Address challenges for single-page apps • As well as mobile devices 42
  43. 43. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ React JavaScript Library • Developed at Facebook and Instagram • Virtual DOM with automatic DOM updates, fast, efficient • Supports server-side rendering (outside of DOM) • Fast adoption by major Internet players • Facebook/Instagram, Yahoo!, Netflix, Airbnb, etc. 43
  44. 44. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Server-Side Rendering • For React adopters, server-side rendering has significant benefits • Faster load time, pre-generated HTML for web apps • Search-engine friendly • Client-centric UI still possible (e.g. Phonegap) 44
  45. 45. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring 4.2 and React • New view templating choice for JSR-223 scripting engines • ScriptTemplateView , ViewResolver, and Configurer • Configuration very similar to the alternatives (e.g. FreeMarker) • Use with Nashorn JavaScript engine from JDK 8 45
  46. 46. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Additional Talks Isomorphic Templating With Spring Boot, Nashorn and React by Sebastien Deleuze Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js by Matt Raible 46
  47. 47. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ HTTP Byte Ranges 47
  48. 48. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Byte Ranges • HTTP 1.1 supports ability to download partial content • RFC 7233 • Server advertises willingness via Accept-Ranges response header • Client can then send a Range request header • e.g. Range: bytes=500-999 • Large media files, request any part / resume … 48
  49. 49. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Byte Range Support in Spring 4.2 • HttpRange to create and parse ranges • Accept-Range and Range exposed in HttpHeaders • ResourceHttpRequestHandler supports byte ranges • e.g. server video files to iOS devices 49
  50. 50. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ $ curl -v --range 0-99 http://localhost:8080/assets/jquery-2.1.4.js > GET /assets/jquery-2.1.4.js HTTP/1.1 > Range: bytes=0-99 ... < HTTP/1.1 206 Partial Content < ... < Accept-Ranges: bytes < Content-Range: bytes 0-99/247597 < Content-Length: 100 < ... 50 Example
  51. 51. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Client Side 51
  52. 52. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ RestTemplate with OkHttp • RestTemplate + AsyncRestTemplate can be used with OkHttp • lightweight HTTP library • HTTP library support • JDK • Apache HttpComponents • Netty • OkHttp 52
  53. 53. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Flexible URI Template Handling • UriTemplateHandler for use with RestTemplate • Default implementation delegates to UriComponentsBuilder • Can be configured to • insert prefix in all URI templates • switch from path to path segment encoding by default • Potential to plug in 3rd party URI template library • e.g. full RFC 6570 syntax 53
  54. 54. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ WebSocket Messaging 54
  55. 55. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Simple Broker: Heartbeats @Configuration @EnableWebSocketMessageBroker static class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { // … @Override public void configureMessageBroker(MessageBrokerRegistry registry) { registry.enableSimpleBroker("/topic").setTaskScheduler(scheduler()); } @Bean @Primary public TaskScheduler scheduler() { return new ThreadPoolTaskScheduler(); } } 55 Enable
  56. 56. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Simple Broker: Selector Expression 56 • Add selector header on subscribe client.subscribe("/topic/interval", function(message) { // ... }, {'selector' : 'headers.parity == 'even''}); • SpEL expression evaluated against messages • Only matching messages received
  57. 57. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Multi-Server User Destinations 57 • Spring supported special STOMP destination • /user/{username}/… • User receives message if connected • User can be connected to any application server (since 4.2)
  58. 58. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Multi-Server User Destinations 58 Spring App RabbitMQ Browser Sergi /user/sergi/…
  59. 59. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Connected User Information • SimpUserRegistry bean • Expose information about connected users and subscriptions • Supported in multi-server scenarios • via UserRegistryMessageHandler • Broadcast local user registry to other servers (via broker relay) • every 10 seconds • remote registry info expires after 20 seconds 59
  60. 60. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ STOMP Client • Supported over WebSocket + over TCP • Plug in any Spring WebSocketClient implementation • SockJsClient allows using STOMP over WebSocket/SockJS • Support for heartbeats, receipts 60
  61. 61. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Programming Model • Property placeholders for @MessageMapping methods • @JsonView on @Payload arguments • Destination template variables in @SendTo annotation • Async return value types • org.springframework.util.concurrent.ListenableFuture • CompletableFuture/CompletionStage (JDK 8) 61
  62. 62. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Programming Model • @ControllerAdvice + @MessageExceptionHandler methods • HandlerMethod arguments for @MessageExceptionHandler • Spring OXM Marshaller based MessageConverter 62
  63. 63. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Related Talk From Zero to Hero with Spring WebSocket by Sergi Almar 63
  64. 64. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 64 Thank You for Listening! @rstoya05 Learn More. Stay Connected. @springcentral Spring.io/video

×