Message driven architecture with spring – the server side java symposium

Mark Fisher has a cool twitter handle @m_f_
Pardon the lack of formatting, there was just too much information to learn plus watch live demos and type lists on an ipad. I will clean it up over the weekend. [cleaned up] Too much content is a good “problem” for a presentation to have.

libraries:

  1. Spring Integration
  2. Spring AMQP in release candidate mode.  Similar to Spring JMS but doesn’t hide it behind JMS. AMQP is an open wireless protocol.  Also use you set up a routing exchange and set up a routing key for clients to bind to.  For example news.star.us so can subscribe to different levels on broker. works with non Java clients

Events

  • Has been in Spring since the very beginning
  • interface ApplicationEventPublisherAware allows you to make a callback
  • Interface ApplicationListener is called when event occurs, can use generics to say what type of events you care about
  • Can do without forcing to extend spring interface as well

Messaging

  • JmsTemplate – prefer CachingConnectionFactory to ensure sessions are reused
  • Jms:listener-container defined in xml on a pojo
  • Or use AmqpTemplate instead of JmsTemplate to use amqp, works the same as jmstemplate, for example you can call receive/send methods
  • Amqp namespace released this week to support listeners
  • Showed demo with rabbitmq including using web ui to see how many messages on queue
  • RestTemplate for http messaging, can use HttpMessageConverters if need to be more specific

Mail

  • SimpleMailMessage to create a message and inject MailSender to send it, good for simple messages, there is a mime one for more complex messsages
  • Core Spring cannot receive e-mail. Spring Integration can

Polling

  • Better to use events/messaging and only poll when you have to
  • Lifecycle interface – start(), stop() and isRunning()
  • SmartLifecycle does those three plus autostartup, phases and adds a callback on stop

Scheduling

  • taskScheduler interface lets you schedule one time tasks, tasks at a fixed rate and tasks at a fixed delay
  • Trigger interface lets you control the next execution time along with the Trigger Context that gives information about the last scheduled/actual time
  • This means you don’t need quartz for simple operations
  • The @Scheduled annotation lets you specify cron or fixed time/delay expressions instead of interfaces
  • Can also create your own annotations to externalize the cron expression so using your custom annotation without duplicating the configuration of the cron expression

Pipes and filters

  • Message can be any object as the payload with headers in a map, the message is immutable unless your payload itself is mutable
  • MessageChannel can do point to point or publish subscribe, set channel, types in xml using  and can also set whether async
  • A gateway can be one way or bidirectional
  • Can use @publisher to put the result of a method or argument to go on a channel as a side effect of calling the method
  • Filters return booleans
  • Router directs to proper channel name
  • Can route on payload type, header type etc
  • Can split/aggregate channels
  • Spring Integration 2.0 lets you use el to specify bindings, etc
  • Can chain when don’t need explicit channel names

What makes standards stick – the server side java symposium

EnterpriseDB is talking about standards in the contest of PAAS (platform as a service). Looking at the forefront of a paradigm shift with cloud.

Java has been number one on the tiobe index for five years. Objective C is currently at number eight. It is an interesting measure because it uses number of jobs, books, etc to calculate rankings.  Java was an evolution of C++ and solved a problem.

Evolution needs to happen or there is that opportunity for something else to replace it.

J2EE was successful because the major companies backed it on day one. Part succeeded (servlets) while art failed (ejb) [jdbc listed as success, but that isn’t jee]. EJB was too complex and alternatives came up like Hibernate and Spring.   The speaker did credit the mess up of EJB with people adopting Spring.

“open source became an alternative to a deficient standard”

Success criteria: solve a problem, developers love, standardize, be open source, be first. Do not need all of these, but more help.  Also listed Microsoft support as a benefit

There were a few typos in the presentation which i found distracting.  Basically the session was a history lesson with some interesting points. I was relieved was not a sales pitch.

Once people move on, they don’t come back. Even though EJB 3.1 is “as good as” Spring, people have already switched.
Who will own the cloud? Who knows? Time will tell.

Performance tuning – the server side java symposium

The presenter started with a disclaimer.  Not for legal like Oracle.  To emphasize that advice needs common sense and to be checked for applicability to your system.

Applications are slow because they are waiting for something. Need to find out what that is.  We generally start looking in our application. But we should start with a larger view of hardware/os,  jvm/memory, and actors/usage patterns.

Tips

  • Make sure your test system is as close to production as possible. This includes the amount of data so you aren’t caching away your problem. In other words, you want to make sure you are solving the right problem.
  • keep going until meets requirements or user decides to stop paying for performance improvements, whichever comes first
  • Remember to benchmark before/after each change so know if worked and the impact
  • Know how much CPU you can use. Even if you are only using forty percent, adding CPU does not help if you are only allocated forty percent
  • Knowing which process using CPU helps. Is it your algorithms or the JVM for garbage collection or nothing in which case it is waiting on some other resource
  • After CPU, go on to other diagnostics such as memory, paging, etc
  • Want system to be calm when testing so can use CPU as a benchmark

The Tooling
The presenter ran an example to walk through the tools

  • Added XX:PrintGCDetails
  • JMeter – shows average time for points of interest real time. Both in numeric format and in a running graph.  Found an out of memory error. Noted better to analyze garbage collection before increasing memory
  • VisualVM – use memory profile to profile object allocations and GC. The count will show objects leaking because it will survive every attempt to collect and create more. The increasing generational count will show the leak.  Note you can instrument every X counts instead of each one to save space.  Can see it happen real time as you run.  Then you can take a snapshot [ the snapshot view is what I’m used to seeing for CodeRanch work]. The monitoring tab shows in graphical format. the heap analysis shows all instances of objects of a certain type. Pick on at random and see heap walk. Select nearest GC root, this takes a minute or so.  The GC root is what is anchoring it to live memory.
  • Visual VM – use threads view to see if thread pool can be increased. Are there enough threads servicing the number of users?  One way to tune is to set the thread pool size larger and then scale back until it is good.
  • GC.log – a number of graphs on garbage collection statistics – how long it takes, distribution, etc
  • Censum – garbage collection log analysis tool that hasn’t been released yet. It shows stats and distributions on the generations