Microservices Expo Authors: Pat Romanski, Dalibor Siroky, Stackify Blog, Elizabeth White, Liz McMillan

Related Topics: Java IoT

Java IoT: Article

Distributed Logging Using The JMS

Distributed Logging Using The JMS

Every software system has logging requirements so application processing can be monitored and tracked. Modern distributed systems, which are usually based on application frameworks, require a logging solution that can cope with multiple processes on multiple hosts sending logging information to a single logging service.

Many application frameworks widely used today, whether they're high-level frameworks like J2EE application servers or low-level frameworks like CORBA ORBs, don't provide a distributed logging facility for application code. Using JMS queues to log application messages is a portable, framework-independent way to efficiently log messages in a distributed system.

Distributed Logging Solutions
It's usually a given that a distributed application needs to keep a centralized application log. We've seen many ad hoc solutions, which are often implemented on a per-application basis. A common way to develop these logging servers is to use low-level APIs, often with the C or Java socket APIs. Logging clients connect by opening a socket and pushing bytes to a log service. Since socket programming is low-level and often error-prone, the logging services are sometimes constructed with an RPC-based distributed object framework such as CORBA or RMI. This provides a higher layer of abstraction to work with, but it still means application developers have to build fundamental application services instead of focusing on the most important task at hand - building real business solutions.

Homegrown distributed logging services are often based on synchronously logging API calls. This means the logging client is forced to block while the logging service processes the message and makes a persistent record in the log. Implementations that support concurrent clients can encounter performance problems related to lock contention in the logging server. In some cases logging services will have internal message queues, so that blocking occurs only through the log message queuing and not throughout the entire logging process. While this approach takes care of the synchronous blocking problem, it's time-consuming and difficult to implement efficiently and reliably, particularly if the solution needs to be coordinated with global or distributed transactions. There are many issues to consider with regard to failure and recovery scenarios for the queue itself and the rules of interaction between the logging client and the logging service under such undesirable conditions.

This matter can be further complicated by geographically dispersed deployments. A distributed application may not be localized to one physical location. Globally distributed applications would presumably need to communicate with the centralized logging system in a secure and reliable fashion over the Internet. As illustrated in Figure 1, you'd likely funnel logging information through intermediate aggregation servers in order to play nice in a firewall environment. These intermediate logging services act as a common conduit that all local applications communicate through. Ideally, these intermediate aggregate servers would be capable of storing log information in case the centralized logging server became temporarily unavailable.

If you were to build a subsystem from scratch that solves all these issues, you'd wind up with something similar to a full-blown JMS queue implementation. Why not use one from the start? It makes perfect sense to base the logging server and its message queue on a common middleware standard and use a common off-the-shelf solution. JMS is an ideal middleware layer that enables distributed logging clients to log messages asynchronously in a uniform and platform-independent way.

It's a natural and pleasant experience to start using JMS to do the same kinds of things that are often done with system-level protocols. JMS has an added advantage as it provides multiple message types for dealing with different kinds of data formats, each with its own set of helper APIs for constructing and deconstructing messages. JMS also accounts for the problems that arise when the intended receivers aren't currently up and running - a crucial advantage for systems that require high reliability and accurate application logging. With JMS, senders and receivers are abstractly decoupled from each other. An application may send a message to an intended receiver, even when the receiver is not available. The JMS system stores messages on the receiver's behalf until the receiver is available. These are important system-level services that would otherwise have to be written by application programmers who could be more productive developing the actual business applications.

In addition, using JMS as the means for a logging mechanism provides the following benefits:

  • Simple, yet flexible standards-based API to be commonly shared among all applications.
  • Nonblocking asynchronous placement of log data into the log queue.
  • Guaranteed once-and-only-once delivery of critical log data to the centralized logging application.
  • Well-defined messaging models and message delivery semantics.
  • High availability of logging services. Error conditions and the complexities of failure scenarios are handled transparently by the JMS provider or in the interface between the application code and the JMS provider.
As shown in Figure 2, substituting a JMS system as the mechanism for delivering the log data to the centralized logging server removes a great deal of complexity that you would have had to build and manage.

JMS provides support for two messaging paradigms, publish/subscribe and queuing. Publish/subscribe is a broadcast model, which is analogous to an event service. Messages are published to virtual channels called topics and every client registered as a listener for a topic receives the message. Queuing is a point-to-point model. Clients send messages to designated endpoints where messages are en- queued. The message queue is persistent and can be thought of logically as a stack; a message pushed on to a queue will be delivered to a single message consumer. This article uses JMS queues for building application logs.

Logging Queue
Since we're using JMS, the hard work is already done. There's no need to write any infrastructure code at all: JMS provides virtually everything needed for a robust logging service. We need to provide only a logging service implementation that reads the log messages from the queue and does whatever is appropriate for the application. Since the queue is persistent, we don't worry about losing messages. For some JMS implementations, it's necessary to use an administrative console to set up the queue before clients can successfully connect to it. If that's the case, creating an administered object through the console is generally as simple as assigning a name. Self-administered JMS implementations don't require any setup.

Generic Entry Point
To use the queue as a basis for distributed logging, we'll need to define a mechanism for the logging client to write the JMS queue. In general, it's good programming practice to provide a layer of indirection between application code and protocol-specific APIs - the fact that we're using a JMS queue to support distributed logging should be completely transparent. This may be important if you already have a logging subsystem in place.

Migrating each application toward a JMS-based solution can be done separately, obviating the need to coordinate the upgrade of all applications in tandem. In other cases, your application server may provide distributed logging and management capabilities already. Preferably the transport mechanism is dynamically configurable. In Java, this is accomplished with interfaces and Factory classes. Finally, the logging API should be simple and straightforward. Listings 1 and 2 show a simple logging interface and implementation that uses a JMS server to write a log message to a queue. Many applications have more complex log message requirements, so this is an illustrative example.

Access to the client logging implementation is provided by a factory class (see Listing 3).

Log Processing
The logging server may send the data to any number of sources: files, databases, a terminal console, and more. It depends on the specific requirements of the application. In general, simple serialized logging to a file or a terminal console can be accomplished using a JMS MessageListener. The JMS server will automatically serialize messages, eliminating the need for lock management in the logging service code. Listing 4 provides an example of a MessageListener that logs messages to standard err on the terminal screen.

A more complicated logging service might interact with the queue and a database log using global transactions. It might also want to process many messages off the queue concurrently. For these kinds of requirements, an EJB 2.0 message-driven bean may be a more appropriate way to implement the processing logic of the logging service. The EJB container can provide support for global transaction management and concurrent message processing, greatly simplifying the development of the logging service. In addition, the EJB server should provide fault tolerance for the log service itself. In this case, the logging service might have to manage lock contention for writing to log files, but since writing to the log file has been decoupled from application processing by the JMS queue, this doesn't present a performance issue.

J2EE-based applications are hosted by application servers that often run a single logical application in many different virtual machines. This allows the application server to transparently provide scalability and fault tolerance to applications built using J2EE components. Application servers are a perfect use case for a distributed logging facility because the replicated application server instances are all servicing clients of a single application. In most cases it's optimal for the application to use a single log. Servlets and EJBs can simply access a singleton logging client API similar to the one we presented above. JSP developers, on the other hand, shouldn't be forced to write Java code unless it's absolutely necessary. The JSP 1.1 specification provides a facility for writing custom tag extensions. A logging tag could be implemented as shown in Listing 5.

The tag we've defined can be used in a natural way by a JSP developer. Logging to the JMS queue in a JSP becomes as simple as adding a new element to an XML document:

<app:log message="Application successfully processed request." />

Another advantage to using JMS as the basis for distributed logging in a J2EE application is that JMS is a part of J2EE, so a JMS implementation will be provided with the application server. As a practical matter this means a JMS-based logging solution should not incur a large expense.

Beyond J2EE
A J2EE-based application is only one example of a distributed architecture, and J2EE accounts for only a fraction of distributed Java applications. Many Java applications rely on Java RMI or CORBA, directly on JMS, or on a low-level protocol such as Sockets for tying together distributed components. Applications based on any of these protocols and the architectures they suggest can benefit from a distributed log service. All the advantages of building a log service around JMS apply equally well to these applications. Many JMS vendors provide a set of C APIs for their JMS server implementation, which means that JMS can be used as a communication protocol with non-Java applications as well. Thus a JMS-based logging service can be used in a very broad context. It provides a flexible solution for large, heterogeneous enterprise computing environments.

A distributed logging service provides an ideal use-case for JMS. Using JMS, application information can be easily logged to a persistent queue and then processed asynchronously. Application-specific development is pushed to the boundaries of the log processing - time-consuming development of fundamental application services is avoided altogether. JMS also provides fault tolerance and scalability, so the application log can provide highly reliable information. Since EJB 2.0 now integrates JMS into the EJB container, global transactions and support for concurrent message processing can be provided transparently in the logging service.

More Stories By Dave Chappell

David Chappell is vice president and chief technologist for SOA at Oracle Corporation, and is driving the vision for Oracle’s SOA on App Grid initiative.

More Stories By Greg Pavlik

Greg Pavlik is an architect at Oracle. In this role he works on a combination of technology strategy, product development, and standards. He is currently responsible for Oracle’s SOA and Web services offerings. Greg is also the author of Java Transaction Processing (Prentice Hall, 2004).

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

@MicroservicesExpo Stories
While some developers care passionately about how data centers and clouds are architected, for most, it is only the end result that matters. To the majority of companies, technology exists to solve a business problem, and only delivers value when it is solving that problem. 2017 brings the mainstream adoption of containers for production workloads. In his session at 21st Cloud Expo, Ben McCormack, VP of Operations at Evernote, discussed how data centers of the future will be managed, how the p...
The nature of test environments is inherently temporary—you set up an environment, run through an automated test suite, and then tear down the environment. If you can reduce the cycle time for this process down to hours or minutes, then you may be able to cut your test environment budgets considerably. The impact of cloud adoption on test environments is a valuable advancement in both cost savings and agility. The on-demand model takes advantage of public cloud APIs requiring only payment for t...
It has never been a better time to be a developer! Thanks to cloud computing, deploying our applications is much easier than it used to be. How we deploy our apps continues to evolve thanks to cloud hosting, Platform-as-a-Service (PaaS), and now Function-as-a-Service. FaaS is the concept of serverless computing via serverless architectures. Software developers can leverage this to deploy an individual "function", action, or piece of business logic. They are expected to start within milliseconds...
As DevOps methodologies expand their reach across the enterprise, organizations face the daunting challenge of adapting related cloud strategies to ensure optimal alignment, from managing complexity to ensuring proper governance. How can culture, automation, legacy apps and even budget be reexamined to enable this ongoing shift within the modern software factory? In her Day 2 Keynote at @DevOpsSummit at 21st Cloud Expo, Aruna Ravichandran, VP, DevOps Solutions Marketing, CA Technologies, was jo...
You know you need the cloud, but you’re hesitant to simply dump everything at Amazon since you know that not all workloads are suitable for cloud. You know that you want the kind of ease of use and scalability that you get with public cloud, but your applications are architected in a way that makes the public cloud a non-starter. You’re looking at private cloud solutions based on hyperconverged infrastructure, but you’re concerned with the limits inherent in those technologies.
Is advanced scheduling in Kubernetes achievable?Yes, however, how do you properly accommodate every real-life scenario that a Kubernetes user might encounter? How do you leverage advanced scheduling techniques to shape and describe each scenario in easy-to-use rules and configurations? In his session at @DevOpsSummit at 21st Cloud Expo, Oleg Chunikhin, CTO at Kublr, answered these questions and demonstrated techniques for implementing advanced scheduling. For example, using spot instances and co...
The cloud era has reached the stage where it is no longer a question of whether a company should migrate, but when. Enterprises have embraced the outsourcing of where their various applications are stored and who manages them, saving significant investment along the way. Plus, the cloud has become a defining competitive edge. Companies that fail to successfully adapt risk failure. The media, of course, continues to extol the virtues of the cloud, including how easy it is to get there. Migrating...
For DevOps teams, the concepts behind service-oriented architecture (SOA) are nothing new. A style of software design initially made popular in the 1990s, SOA was an alternative to a monolithic application; essentially a collection of coarse-grained components that communicated with each other. Communication would involve either simple data passing or two or more services coordinating some activity. SOA served as a valid approach to solving many architectural problems faced by businesses, as app...
Some journey to cloud on a mission, others, a deadline. Change management is useful when migrating to public, private or hybrid cloud environments in either case. For most, stakeholder engagement peaks during the planning and post migration phases of a project. Legacy engagements are fairly direct: projects follow a linear progression of activities (the “waterfall” approach) – change managers and application coders work from the same functional and technical requirements. Enablement and develo...
Gone are the days when application development was the daunting task of the highly skilled developers backed with strong IT skills, low code application development has democratized app development and empowered a new generation of citizen developers. There was a time when app development was in the domain of people with complex coding and technical skills. We called these people by various names like programmers, coders, techies, and they usually worked in a world oblivious of the everyday pri...
From manual human effort the world is slowly paving its way to a new space where most process are getting replaced with tools and systems to improve efficiency and bring down operational costs. Automation is the next big thing and low code platforms are fueling it in a significant way. The Automation era is here. We are in the fast pace of replacing manual human efforts with machines and processes. In the world of Information Technology too, we are linking disparate systems, softwares and tool...
DevOps is good for organizations. According to the soon to be released State of DevOps Report high-performing IT organizations are 2X more likely to exceed profitability, market share, and productivity goals. But how do they do it? How do they use DevOps to drive value and differentiate their companies? We recently sat down with Nicole Forsgren, CEO and Chief Scientist at DORA (DevOps Research and Assessment) and lead investigator for the State of DevOps Report, to discuss the role of measure...
DevOps is under attack because developers don’t want to mess with infrastructure. They will happily own their code into production, but want to use platforms instead of raw automation. That’s changing the landscape that we understand as DevOps with both architecture concepts (CloudNative) and process redefinition (SRE). Rob Hirschfeld’s recent work in Kubernetes operations has led to the conclusion that containers and related platforms have changed the way we should be thinking about DevOps and...
"As we've gone out into the public cloud we've seen that over time we may have lost a few things - we've lost control, we've given up cost to a certain extent, and then security, flexibility," explained Steve Conner, VP of Sales at Cloudistics,in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
These days, APIs have become an integral part of the digital transformation journey for all enterprises. Every digital innovation story is connected to APIs . But have you ever pondered over to know what are the source of these APIs? Let me explain - APIs sources can be varied, internal or external, solving different purposes, but mostly categorized into the following two categories. Data lakes is a term used to represent disconnected but relevant data that are used by various business units wit...
With continuous delivery (CD) almost always in the spotlight, continuous integration (CI) is often left out in the cold. Indeed, it's been in use for so long and so widely, we often take the model for granted. So what is CI and how can you make the most of it? This blog is intended to answer those questions. Before we step into examining CI, we need to look back. Software developers often work in small teams and modularity, and need to integrate their changes with the rest of the project code b...
"I focus on what we are calling CAST Highlight, which is our SaaS application portfolio analysis tool. It is an extremely lightweight tool that can integrate with pretty much any build process right now," explained Andrew Siegmund, Application Migration Specialist for CAST, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"Cloud4U builds software services that help people build DevOps platforms for cloud-based software and using our platform people can draw a picture of the system, network, software," explained Kihyeon Kim, CEO and Head of R&D at Cloud4U, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Kubernetes is an open source system for automating deployment, scaling, and management of containerized applications. Kubernetes was originally built by Google, leveraging years of experience with managing container workloads, and is now a Cloud Native Compute Foundation (CNCF) project. Kubernetes has been widely adopted by the community, supported on all major public and private cloud providers, and is gaining rapid adoption in enterprises. However, Kubernetes may seem intimidating and complex ...
DevOps is often described as a combination of technology and culture. Without both, DevOps isn't complete. However, applying the culture to outdated technology is a recipe for disaster; as response times grow and connections between teams are delayed by technology, the culture will die. A Nutanix Enterprise Cloud has many benefits that provide the needed base for a true DevOps paradigm. In their Day 3 Keynote at 20th Cloud Expo, Chris Brown, a Solutions Marketing Manager at Nutanix, and Mark Lav...