Posts

Showing posts with the label spring Cloud

Java cfenv example

Java CFEnv is a library for easily accessing the environment variables set when deploying an application to Cloud Foundry. It is modeled after the design of the node library node-cfenv and other -cfenv libraries in the Cloud Foundry ecosystem. The class CfEnv is the entry point to the API for accessing Cloud Foundry environment variables. In a Spring application, you can use the Spring Expression Language to invoke methods on bean of type CfEnv to set properties. CFEnv’s Boot support sets common application properties so that Java objects such as the DataSource or the RabbitConnectionFactory are created using Spring Boot autoconfiguration. The 1.0 M1 blog provides some additional background information. Dependency You can access the stable release from maven central using the coordinates <dependency>   <groupId>io.pivotal.cfenv</groupId>   <artifactId>java-cfenv-boot</artifactId>   <version>2.1.1.RELEASE</version> ...

Spring supplier Example

Non Spring Developers Let us assume for a second that you are not a Spring developer and not familiar with Spring Integration which already provides abstractions for ROME. In that case, we can certainly use ROME directly to produce feed records. For example, this is a valid Supplier for this scenario. public Supplier<SyndEntry> feedSupplier() { return () -> { //Use the ROME framework directly to produce syndicated entries. } } The benefit here is that we can develop the supplier without any knowledge of Spring, and it can be deployed to a serverless environment directly, using the abstractions provided by that environment or by relying on a framework like Spring Cloud Function. This essentially means that if you are a Java developer without much Spring Framework skills, you can still write the functions using just the interfaces defined in the java.util.function package such as Function, Supplier and Consumer, by providing the business logic.  Spring Developers Add ...

Introducing Java Functions for Spring Cloud Stream Applications - Part 1

Last week Spring posted Introducing Java Functions for Spring Cloud Stream Applications - Part 0 to announce the release of Spring Cloud Stream applications 2020.0.0-M2. Here, explore function composition, one of the more powerful features enabled by the function oriented architecture presented in Part 0. If you haven’t had a chance to read Part 0, now would be a great time! Function Composition Function composition has a solid theoretical foundation in mathematics and computer science. In practical terms, it is a way to join a sequence of functions to create a more complex function. Let’s look at a simple example using Java functions. We have two functions, reverse and upper. Each accepts a String as input and produces a String as output. We can compose them using the built-in andThen method. The composite function is itself a Function<String, String>. If you run this, it will print ESREVER. Function<String, String> reverse = s -> new StringBuilder(s).reve...

Java Functions for Spring Cloud Stream Applications

Image
What Has Changed? Java Functions Continual advances in the Java and Spring ecosystem have driven us to rethink our approach. The most significant change is that we have implemented a layered architecture in which the core functionality, previously provided by the app starters, are now provided as Java functions, implementing the standard interfaces found in the java.util.function package. The functional components in this release can be exposed as standard Spring beans and then used for your data integration needs by directly embedding them in an application. By injecting these functions in a custom application, you immediately benefit from the features provided by underlying libraries. For example, Spring Integration adapters are used in many of these functions. You can invoke the function directly, use Spring Cloud Function to invoke it through a REST endpoint, or use it in a serverless environment. Unlike the app starters, the functional components have no dependency on Sprin...