Statistics
40
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2025-12-07

AuthorMarkus Eisele, Natale Vinto

While containers, microservices, and distributed systems dominate discussions in the tech world, the majority of applications in use today still run monolithic architectures that follow traditional development processes. This practical book helps developers examine long-established Java-based models and demonstrates how to bring these monolithic applications successfully into the future. Relying on their years of experience modernizing applications, authors Markus Eisele and Natale Vinto walk you through the steps necessary to update your organization's Java applications. You'll discover how to dismantle your monolithic application and move to an up-to-date software stack that works across cloud and on-premises installations. Learn cloud native application basics to understand what parts of your organization's Java-based applications and platforms need to migrate and modernize Understand how enterprise Java specifications can help you transition projects and teams Build a cloud native platform that supports effective development without falling into buzzword traps Find a starting point for your migration projects by identifying candidates and staging them through modernization steps Discover how to complement a traditional enterprise Java application with components on top of containers and Kubernetes ----------------------------- Markus is a Java Champion, former Java EE Expert Group member, founder of JavaLand, reputed speaker at Java conferences around the world, and a very well known figure in the Enterprise Java world. With more than 16 years of professional experience in the industry, he designed and developed large Enterprise grade applications for Fortune 500 companies. As an experienced team lead and architect, he helped implement some of the largest integration projects in automotive, finance and insurance companies. More than 12 years of international speaking experience and 5 years in developer advocacy with a strong focus on Java platforms helped him bu

Tags
No tags
ISBN: 1098102142
Publisher: O'Reilly Media
Publish Year: 2021
Language: 英文
Pages: 164
File Format: PDF
File Size: 6.2 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Eisele & Vinto M od ernizing Enterp rise Ja va M od ernizing Enterp rise Ja va Modernizing Enterprise Java A Concise Cloud Native Guide for Developers Markus Eisele & Natale Vinto
JAVA / PROGR AMMING “Taking heritage forward successfully is one of the biggest challenges for our customers. Natale and Markus outline the methodology and the technologies that will power your journey.” —Ashesh Badani SVP Products, Red Hat Inc. Modernizing Enterprise Java ISBN: 978-1-098-10214-2 US $59.99 CAN $79.99 Twitter: @oreillymedia facebook.com/oreilly While containers, microservices, and distributed systems dominate discussions in the tech world, the majority of applications in use today still run monolithic architectures that follow traditional development processes. This practical book helps developers examine long-established Java-based models and demonstrates how to bring these monolithic applications successfully into the future. Relying on their years of experience modernizing applications, authors Markus Eisele and Natale Vinto walk you through the steps necessary to update your organization’s Java applications. You’ll discover how to dismantle your monolithic application and move to an up-to-date software stack that works across cloud and on-premises installations. • Learn cloud native application basics to understand what parts of your organization’s Java-based applications and platforms need to migrate and modernize • Understand how enterprise Java specifications can help you transition projects and teams • Build a cloud native platform that supports effective development without falling into buzzword traps • Find a starting point for your migration projects by identifying candidates and staging them through modernization steps • Discover how to complement a traditional enterprise Java application with components on top of containers and Kubernetes Markus Eisele is the developer adoption program lead for Red Hat in EMEA. He has been working with Java EE servers from different vendors for more than 14 years. He is a Java Champion, former Java EE Expert Group member, and founder of Germany’s number-one Java conference, JavaLand. Natale Vinto is a software engineer with more than 10 years of expertise on IT and ICT technologies and a consolidated background on telecommunications and Linux operating systems. Today, Natale is a developer advocate for OpenShift at Red Hat, helping people within communities and customers have success with their Kubernetes and cloud native strategy. Eisele & Vinto M od ernizing Enterp rise Ja va M od ernizing Enterp rise Ja va
Markus Eisele and Natale Vinto Modernizing Enterprise Java A Concise Cloud Native Guide for Developers Boston Farnham Sebastopol TokyoBeijing
978-1-098-10214-2 [LSI] Modernizing Enterprise Java by Markus Eisele and Natale Vinto Copyright © 2022 Markus Eisele and Natale Vinto. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com. Acquisitions Editor: Suzanne McQuade Development Editors: Nicole Taché, Amelia Blevins Production Editor: Caitlin Ghegan Copyeditor: Piper Editorial Consulting, LLC Proofreader: Pider Editorial Consulting, LLC Indexer: nSight, Inc. Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Kate Dullea November 2021: First Edition Revision History for the First Edition 2021-10-20: First Release See https://oreil.ly/W0Bne for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Modernizing Enterprise Java, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the authors, and do not represent the publisher’s views. While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. This work is part of a collaboration between O’Reilly and Red Hat. See our statement of editorial independence.
To my family. None of this would be possible without them. —Markus To Fabrizio Scarcello, modernizer, innovator, dear friend. —Natale
(This page has no text content)
Table of Contents From Platform to Ecosystem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi 1. Revisiting Enterprise Development. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 From Public to Private. Why Clouds? 2 What “Cloud Native” Means 3 Kubernetes-Native Development 4 Containers and Orchestration for Developers 4 Container-Native Runtime 4 Kubernetes Flavors 5 Managing Development Complexity 5 DevOps and Agility 8 Summary 9 2. The Path to Cloud Native Java. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Cloud Native Workshop 11 Architecture 12 Create an Inventory Microservice with Quarkus 13 Create Quarkus Maven Project 14 Create a Domain Model 17 Create a RESTful Service 19 Run the App in Dev Mode 20 Create a Catalog Microservice with Spring Boot 23 Create a Maven Project 23 Create a Domain Model 26 Create a Data Repository 28 Create a RESTful Service 29 v
Create a Gateway Service with Vert.x 33 Create a Vert.x Maven Project 34 Create an API Gateway 36 Create a Frontend with Node.js and AngularJS 41 Run the Frontend 42 Summary 44 3. Travel Light on Your Pathway. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Three-Tier or Distributed System 45 Technology Updates, Modernization, and Transformation 46 The 6 Rs 47 Divide and Containerize 50 Kubernetes as the New Application Server? 50 Define Your Target Platform 54 Mandatory Migration Steps and Tools 56 Create an Application Portfolio 57 Prepare for Big Things 57 Summary 59 4. A Kubernetes-Based Software Development Platform. . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Developers and Kubernetes 61 What Kubernetes Does 62 What Kubernetes Doesn’t Do 63 Infrastructure as a Code 63 Container Images 64 Dockerfile 65 Building Container Images 66 Run Containers 67 Registry 68 Deploying to Kubernetes 69 Pod 69 Service 71 Deployment 73 Kubernetes and Java 76 Jib 76 JKube 78 Summary 83 5. Beyond Lift and Shift: Working with Legacy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Managing Legacy 86 Assessing Applications for Migration 86 Assessing Functionality for Migration 91 vi | Table of Contents
Migration Approaches 92 Protecting Legacy (Replatform) 92 Build Something New (Refactor) 95 Challenges 98 Avoiding Dual-Writes 98 Long-Running Transactions 99 Removing Old Code Too Quickly 99 Integration Aspects 99 Summary 100 6. Building Kubernetes-Native Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Find the Right Balance Between Scalability and Complexity 101 Functional Requirements for Modern Architectures 102 API-Driven 103 Discovery 104 Security and Authorization 104 Monitoring 105 Tracing 106 Logging 106 CI/CD 107 Debugging Microservices 110 Port Forwarding 111 Quarkus Remote Development Mode 112 Telepresence 113 Summary 115 7. Tomorrow’s Solutions: Serverless. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 What Is Serverless? 117 Architectural Evolution 118 Use Cases: Data, AI, and Machine Learning 119 Use Cases: Edge Computing and IoT 120 Knative: Serverless for Kubernetes 121 Event-Driven Serverless Architectures 123 Function as a Service for Java Applications 126 Functions Deployment for Java Applications 127 Boson Function CLI (func) 127 Summary 136 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Table of Contents | vii
(This page has no text content)
From Platform to Ecosystem Unless you’ve been in deep seclusion for the past few years, you can’t have missed the fact that the enterprise world has been moving toward adopting cloud technologies. This includes approaches such as microservices, Kubernetes, Linux containers, and so much more. However, despite the fact that Java has been the mainstay of enterprise developers for over two decades, it hasn’t been immediately obvious that it has such a significant role in this new cloud world. Java and the frameworks and stacks built with it are often viewed as monolithic, and slow to start, consuming a lot of memory or disk space, and the dynamic nature of Java itself seems to fly in the face of Kubernetes’s immutability assumptions. For the many millions of Java developers out there, this could pose a serious problem, espe‐ cially if we need to try to re-create in another language the richness of the Java eco‐ system of IDEs, third party libraries, etc., which have helped to make developers so incredibly productive over the years. Fortunately, the Java community of developers and vendors has met the challenge of cloud native Java head on. Changes in the Java language, frameworks, etc. have been made and adopted quickly, allowing Java developers to bring their skills to this new frontier. These include technologies such as Quarkus, GraalVM, Eclipse Vert.x, Spring Boot, and OpenJDK. However, using them efficiently within a cloud environment is not always obvious. Where does CI/CD come into play? What about Linux container images and Kuber‐ netes? Monitoring, observability, health checking of your microservices, and so much more can appear to be a daunting challenge, even for the most experienced developer. ix
Fortunately, in this book, Markus and Natale have provided the answers. Within these pages, you’ll be taken through a journey of understanding and appreciation of what’s happening within the Java world to better embrace cloud and also those technologies within the cloud that may not be familiar and yet are important to ensure your dis‐ tributed microservices function well. Whether you’re an experienced Java developer or a relative novice, this book is a great starting point for your journey into the cloud and beyond! — Mark Little Vice President, Middleware Engineering, Red Hat x | From Platform to Ecosystem
Preface We wrote this book for developers who are looking to bring their monolithic, Java- based models successfully into the future. The roadmap for the book is as follows: • Chapter 1 presents the fundamental technologies and concepts we will use throughout the book. • Chapter 2 walks you through a complete microservices-based architecture imple‐ mentation, using different Java frameworks for different components. We’ll give an overview on how to split the typical monolithic approach into a more diverse and heterogeneous environment. • Chapter 3 presents some basic migration strategies and shows you an evaluation path for the target development platform. • Chapter 4 discusses how Java developers can benefit from Kubernetes capabilities to modernize and enhance their apps. • Chapter 5 explores proven patterns, standardized tools, and open source resources that will help you create long-lasting systems that can grow and change with your needs. • Chapter 6 demonstrates essential tasks in Kubernetes, such as logging, monitor‐ ing, and debugging apps. • Chapter 7 analyzes how Java developers can create modern applications follow‐ ing a serverless execution model. We outlined some of the most common use cases and architectures that Java developers are likely to work with today and tomorrow. xi
Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program ele‐ ments such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values deter‐ mined by context. This element signifies a tip or suggestion. This element signifies a general note. This element indicates a warning or caution. Using Code Examples Supplemental material (code examples, exercises, etc.) is available for download at https://oreil.ly/modernentjava. If you have a technical question or a problem using the code examples, please send email to bookquestions@oreilly.com. xii | Preface
This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require per‐ mission. We appreciate, but generally do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Modernizing Enterprise Java by Markus Eisele and Natale Vinto (O’Reilly). Copyright 2022 Markus Eisele and Natale Vinto, 978-1-098-10214-2.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com. O’Reilly Online Learning For more than 40 years, O’Reilly Media has provided technol‐ ogy and business training, knowledge, and insight to help companies succeed. Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other publishers. For more information, visit http://oreilly.com. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at https://oreil.ly/ModernJava. Preface | xiii
Email bookquestions@oreilly.com to comment or ask technical questions about this book. For news and information about our books and courses, visit http://oreilly.com. Find us on Facebook: http://facebook.com/oreilly. Follow us on Twitter: http://twitter.com/oreillymedia. Watch us on YouTube: http://youtube.com/oreillymedia. Acknowledgments We both want to thank Jason “Jay” Dobies for his wild passion for getting through our German/Italian English. He not only helped us to be better writers but also gave valuable insight as an early reader. Thank you for having been part of this journey. Everybody says writing a book isn’t easy. We did know that before we started. What we bluntly underesti‐ mated was the fact that we started writing at the beginning of a pandemic. We both went through more ups and downs than expected, and it is only because of our families and friends that we even got an opportunity to finish this book. We also can’t praise the O’Reilly team enough for their patience, flexible deadlines, and open ears when we needed them. Thank you, Suzanne McQuade, Nicole Taché, and Amelia Blevins! Thank you, Red Hat. For providing an amazing place to work, learn, and grow. We love open source and sharing knowledge as much as probably everybody else in this company. To the many “Hatters” for their support on the way! Technical reviewers catch you at your weakest. Whenever we tried to sneak a little detail by them, they found it and asked the right questions. Thank you all for your dedication and inspirations along the way: Sébas‐ tien Blanc, Alex Soto, and Marc Hildenbrand! The heart of this book is not only the com‐ bined experience accumulated by us but first and foremost an example. This example was initialy created by Madou Coulibaly and Alex Groom. They used this to teach many developers how to effectivly build cloud native applications and allowed us to use their consise example as the base. #stayHealthy #wearAMask #protectYourLovedOnes xiv | Preface
CHAPTER 1 Revisiting Enterprise Development Enterprise development has always been one of the most exciting fields of software engineering, and the last decade has been a particularly fascinating period. The 2010s saw highly distributed microservices gradually replace classic three-tier architectures, with the almost limitless resources of cloud-based infrastructure pushing heavy‐ weight application servers toward obsolescence. While developers are challenged with putting the pieces of the distributed world back together, plenty of voices ques‐ tion the necessity for this complex microservices world. The reality is that most appli‐ cations are still well-crafted monolithic applications that follow a traditional software development process. However, the way we deploy and operate software has changed equally fast. We have seen DevOps growing into GitOps, expanding developers’ responsibilities beyond the application code including the required infrastructure. Building on Markus’s book Modern Java EE Design Patterns (O’Reilly), this book puts more perspective on mod‐ ernization than just modularization. We want to help you understand the various pieces that lead to a modern Kubernetes-native development platform and how to build and maintain applications on top of it. This book aims to step back and evaluate the success factors and drivers for applica‐ tion modernization and cloud native architectures. We focus on modernizing Java- based Enterprise Applications, including a selection process for which applications are suitable for modernization and an overview of tools and methodologies that help you manage your modernization efforts. Instead of talking about patterns, this book provides a set of examples to help you apply everything you’ve learned. That said, this book isn’t discussing monolithic versus distributed applications exten‐ sively. Rather, our goal is to help you understand how to seamlessly move your appli‐ cations to the cloud. 1
You can use this book as a reference and read chapters in any order. We have organ‐ ized the material, though, starting with higher-level concepts to implementation in iterations. First, it’s important to start by looking at the different definitions of clouds and how we build applications for them. From Public to Private. Why Clouds? The differences between public clouds, private clouds, hybrid clouds, and multiclouds were once easily defined by location and ownership. Today, these two are no longer the only relevant drivers for the classification of clouds. Let’s start with a more com‐ prehensive definition of the different target environments and why they are used. A public cloud environment is usually created from resources not owned by the end user that can be redistributed to other tenants. Private cloud environments solely dedicate their resources to the end user, usually within the user’s firewall, data center, or sometimes on premises. Multiple cloud environments with some degree of work‐ load portability, orchestration, and management are called hybrid clouds. Decoupled, independent, and not connected clouds are commonly referred to as multiclouds. Hybrid and multicloud approaches are mutually exclusive; you can’t have both simul‐ taneously because the clouds will either be interconnected (hybrid cloud) or not (multicloud). Deploying applications to a cloud, regardless of the type of cloud, is becoming more common across enterprises as they seek to improve security and performance through an expanded portfolio of environments. But security and performance are only two of many reasons to move workloads into hybrid or multicloud environ‐ ments. The primary motivation for many is the pay-for-what-you-use model. Instead of investing in costly on-premises hardware that is hard and expensive to scale out, clouds offer resources when you need them. You don’t have to invest in facilities, util‐ ities, or building out your own data center. You do not even need dedicated IT teams to handle your cloud data center operations, as you can enjoy the expertise of your cloud provider’s staff. For developers, the cloud is about self-service and flexibility. You don’t have to wait for environments to be promoted, and you can choose infrastructure components (e.g., databases, message brokers, etc.) as the need arises to free you from unnecessary wait times and ultimately speed up development cycles. Beyond these primary advan‐ tages, you can also find custom features for developers in some cloud environments. OpenShift, for example, has an integrated development console that provides devel‐ opers with direct edit access to all details of their application topology. Cloud-based IDEs (e.g., Eclipse Che) provide browser-based access to development workspaces and eliminate local environment configuration for teams. 2 | Chapter 1: Revisiting Enterprise Development
Additionally, cloud infrastructures encourage you to automate your deployment pro‐ cesses. Deployment automation enables you to deploy your software to testing and production environments with the push of a button—a mandatory requirement for Agile development and DevOps teams. You’ve seen a need for 100% automation already when you’ve read about microservices architectures. But automation goes well beyond the application parts. It extends to the infrastructure and downstream systems. Ansible, Helm, and Kubernetes Operators help you. We talk more about automation in Chapter 4, and you’ll use an Operator in Chapter 7. What “Cloud Native” Means You’ve probably heard of the cloud native approach for developing applications and services, and even more so since the Cloud Native Computing Foundation (CNCF) was founded in 2015 and released Kubernetes v1. Bill Wilder first used the term “cloud native” in his book, Cloud Architecture Patterns (O’Reilly). According to Wilder, a cloud native application is architected to take full advantage of cloud plat‐ forms by using cloud platform services and scaling automatically. Wilder wrote his book during a period of growing interest in developing and deploying cloud native applications. Developers had various public and private platforms to choose from, including Amazon AWS, Google Cloud, Microsoft Azure, and many smaller cloud providers. But hybrid-cloud deployments were also becoming more prevalent around then, which presented challenges. The CNCF defines “cloud native” as: cloud native technologies empower organizations to build and run scalable applica‐ tions in modern, dynamic environments such as public, private, and hybrid clouds. Containers, service meshes, microservices, immutable infrastructure, and declarative APIs exemplify this approach. These techniques enable loosely coupled systems that are resilient, manageable, and observable. Combined with robust automation, they allow engineers to make high- impact changes frequently and predictably with minimal toil. —CNCF Cloud Native Definition v1.0 Similar to cloud native technologies are the Twelve-Factor Apps. The Twelve-Factor Apps manifesto defines patterns for building applications that are delivered on the cloud. While these patterns overlap with Wilder’s cloud architecture patterns, the Twelve-Factor methodology can be applied to apps written in any programming lan‐ guage and use any combination of backing services (database, queue, memory cache, etc.). What “Cloud Native” Means | 3
Kubernetes-Native Development For developers deploying applications to a hybrid cloud, shifting focus from cloud native to Kubernetes-native makes sense. One of the first mentions of “Kubernetes- native” is found as early as 2017. A blog post on Medium describes the differences between Kubernetes-native and cloud native as a set of technologies that are opti‐ mized for Kubernetes. The key takeaway is that Kubernetes-native is a specialization of cloud native and not separated from what cloud native defines. Whereas a cloud native application is intended for the cloud, a Kubernetes-native application is designed and built for Kubernetes. In the early days of cloud native development, orchestration differences prevented applications from being genuinely cloud native. Kubernetes resolves the orchestration problem, but Kubernetes does not cover cloud provider services (for example, Roles and Permissions) or provide an event bus (for example, Kafka). The idea that Kubernetes-native is a specialization of cloud native means that there are many simi‐ larities between them. The main difference is cloud provider portability. Taking full advantage of the hybrid cloud and using multiple cloud providers requires that appli‐ cations are deployable to any cloud provider. Without such a feature, you’re tied into a single cloud provider and reliant on them being up 100% of the time. To fully use the benefits of a hybrid cloud, applications have to be build in a Kubernetes-native way. Kubernetes-native is the solution to cloud portability concerns. We talk more about Kubernetes-native in Chapter 2. Containers and Orchestration for Developers One key ingredient for portability is the container. A container represents a fraction of the host system resources together with the application. The origins of containers go back to early Linux days with the introduction of chroots, and they became main‐ stream with Google’s process containers, which eventually became cgroups. Their use exploded in 2013 primarily because of Docker, which made them accessible for many developers. There is a difference between Docker the company, Docker containers, Docker images, and the Docker developer tooling we’re all used to. While everything started with Docker containers, Kubernetes prefers to run containers through any container runtime (e.g. containerd or CRI-O) that supports its Container Runtime Interface (CRI). What many people refer to as Docker images are actually images packaged in the Open Container Initiative (OCI) format. Container-Native Runtime Containers offer a lighter-weight version of the Linux operating system’s userland stripped down to the bare essentials. However, it’s still an operating system, and the quality of a container matters just as much as the host operating system. It takes a lot 4 | Chapter 1: Revisiting Enterprise Development