+++ /dev/null
----
-title: Archiv - 2013
-linkTitle: 2013
-layout: year
----
+++ /dev/null
----
-categories:
- - jetty
- - less
- - maven
- - wro4j
-date: "2013-12-06T10:58:17+00:00"
-title: Combining jetty-maven-plugin and wro4j-maven-plugin for Dynamic Reloading of LESS-Resources
-url: /combining-jetty-maven-plugin-and-wro4j-maven-plugin-for-dynamic-reloading-of-less-resources/
----
- <p>Ever searched for a simple configuration, that lets you use your <a href="http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://wiki.eclipse.org']);" title="See the documentation for mor information">jetty-maven-plugin</a> as you are used to, while working with <a href="http://www.csscss.org/" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://www.csscss.org']);" title="See LESS CSS documentation for mor informations">LESS</a> to simplify your stylesheets?</p>
- <p>You cannot do both, use the <a href="http://www.csscss.org/#usage" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://www.csscss.org']);" title="More about the client-side usage of LESS">Client-side mode</a> of LESS to ease development and use the <a href="https://github.com/marceloverdijk/lesscss-maven-plugin" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://github.com']);" title="Homepage of the official LESS CSS maven plugin">lesscss-maven-plugin</a> to automatically compile the LESS-sources into CSS for production. That does not work, because your stylesheets must be linked in different ways if you are switching between the client-side mode – which is best for development – and the pre-compiled mode – which is best for production. For the client-side mode you need something like:</p>
- <pre class="prettyprint linenums"> <code class="html">
- <link rel="stylesheet" type="text/css" href="styles.css" />
- <script src="less.js" type="text/javascript"></script>
- </code>
- </pre>
- <p>While, for the pre-compiled mode, you want to link to your stylesheets as usual, with:</p>
- <pre class="prettyprint linenums"> <code class="html">
- <link rel="stylesheet" type="text/css" href="styles.css" />
- </code>
- </pre>
- <p>While looking for a solution to this dilemma, I stumbled accross <a href="https://code.google.com/p/wro4j/" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://code.google.com']);" title="See the documentation of ths wounderfull tool">wro4j</a>. Originally intended, to speed up page-delivery by combining and minimizing multiple resources into one through the use of a servlet-filter, this tool also comes with a maven-plugin, that let you do the same offline, while compiling your webapp.</p>
- <p>The idea is, to use the <a href="http://code.google.com/p/wro4j/wiki/MavenPlugin" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://code.google.com']);" title="See the documentation of hte wro4j-maven-plugin">wro4j-maven-plugin</a> to compile and combine your LESS-sources into CSS for production and to use the <a href="http://code.google.com/p/wro4j/wiki/Installation" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://code.google.com']);" title="See how to configure the filter">wro4j filter</a>, to dynamically deliver the compiled CSS while developing. This way, you do not have to alter your HTML-code, when switching between development and production, because you always link to the CSS-files.</p>
- <p>So, lets get dirty!</p>
- <h2>Step 1: Configure wro4j</h2>
- <p>First, we configure <strong>wro4j</strong>, like as we want to use it to speed up our page. The details are explained and linked on wro4j’s <a href="http://code.google.com/p/wro4j/wiki/GettingStarted" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://code.google.com']);" title="Visit the Getting-Started-Page">Getting-Started-Page</a>. In short, we just need two files: <strong>wro.xml</strong> and <strong>wro.properties</strong>.</p>
- <h3>wro.xml</h3>
- <p>wro.xml tells wro4j, which resources should be combined and how the result should be named. I am using the following configuration to generate all LESS-Sources beneath <code>base/</code> into one CSS-file called <code>base.css</code>:</p>
- <pre class="prettyprint linenums"> <code class="xml">
- <groups xmlns="http://www.isdc.ro/wro">
- <group name="base">
- <css>/css/base/*.css</css>
- </group>
- </code>
- </pre>
- <p>wro4j looks for <code>/css/base/*.css</code> inside the root of the web-context, which is equal to <code>src/main/webapp</code> in a normal maven-project. There are <a href="http://code.google.com/p/wro4j/wiki/ResourceTypes" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://code.google.com']);" title="See the resource locator documentation of wro4j for more details">other ways to specifie the resources</a>, which enable you to store them elswhere. But this approach works best for our goal, because the path is understandable for both: the wro4j servlet-filter, we are configuring now for our development-environment, and the wro4j-maven-plugin, that we will configure later for build-time compilation.</p>
- <h3>wro.properties</h3>
- <p>wro.properties in short tells wro4j, how or if it should convert the combined sources and how it should behave. I am using the following configuration to tell wro4j, that it should convert <code>*.css</code>-sources into CSS and do that on <em>every request</em>:</p>
- <pre class="prettyprint linenums"> <code class="properties">
- preProcessors=less4j
- disableCache=true
- </code>
- </pre>
- <p>You can do a lot more here. There are countless <a href="http://code.google.com/p/wro4j/wiki/ConfigurationOptions" onclick="javascript:_gaq.push(['_trackEvent', 'outbound-article', 'http://code.google.com']);" title="See all configuration options">configuration options</a> to fine-tune the behaviour of wro4j. The <code>disableCache=true</code> is crucial, because we would not see the changes take effect when developing with <strong>jetty-maven-plugin</strong> later on. You can also do much more with your resources here, for example <a href="https://code.google.com/p/wro4j/wiki/AvailableProcessors" onclick="javascript:_gaq.push(['_trackEvent', 'outbound-article', 'http://code.google.com']);" title="See all available processors">minimizing</a>. But for our goal, we are now only intrested in the compilation of our LESS-sources.</p>
- <h2>Step 2: Configure the wro4j servlet-filter</h2>
- <p>Configuring the filter in the <strong>web.xml</strong> is easy. It is explained in wro4j’s <a href="https://code.google.com/p/wro4j/wiki/Installation" onclick="javascript:_gaq.push(['_trackEvent', 'outbound-article', 'http://code.google.com']);" title="See the installation instructions for the wro4j servlet-filter">installation-insctuctions</a>. But the trick is, that we do not want to configure that filter for the production-version of our webapp, because we want to compile the resources offline, when the webapp is build. To acchieve this, we can use the <code><overrideDescriptor></code>-Parameter of the <a href="http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin#Configuring_Your_WebApp" onclick="javascript:_gaq.push(['_trackEvent', 'outbound-article', 'http://wiki.eclipse.org']);" title="Read more about the configuration of the jetty-maven-plugin">jetty-maven-plugin</a>.</p>
- <h2><overrideDescriptor></h2>
- <p>This parameter lets you specify additional configuration options for the web.xml of your webapp. I am using the following configuration for my jetty-maven-plugin:</p>
- <pre class="prettyprint linenums"> <code class="xml">
- <plugin>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-maven-plugin</artifactId>
- <configuration>
- <webApp>
- <overrideDescriptor>${project.basedir}/src/test/resources/jetty-web.xml</overrideDescriptor>
- </webApp>
- </configuration>
- <dependencies>
- <dependency>
- <groupId>ro.isdc.wro4j</groupId>
- <artifactId>wro4j-core</artifactId>
- <version>${wro4j.version}</version>
- </dependency>
- <dependency>
- <groupId>ro.isdc.wro4j</groupId>
- <artifactId>wro4j-extensions</artifactId>
- <version>${wro4j.version}</version>
- <exclusions>
- <exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- </exclusion>
- <exclusion>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- </exclusion>
- <exclusion>
- <groupId>commons-pool</groupId>
- <artifactId>commons-pool</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.google.javascript</groupId>
- <artifactId>closure-compiler</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.github.lltyk</groupId>
- <artifactId>dojo-shrinksafe</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.jruby</groupId>
- <artifactId>jruby-core</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.jruby</groupId>
- <artifactId>jruby-stdlib</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.jruby</groupId>
- <artifactId>jruby-stdlib</artifactId>
- </exclusion>
- <exclusion>
- <groupId>me.n4u.sass</groupId>
- <artifactId>sass-gems</artifactId>
- </exclusion>
- <exclusion>
- <groupId>nz.co.edmi</groupId>
- <artifactId>bourbon-gem-jar</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.codehaus.gmaven.runtime</groupId>
- <artifactId>gmaven-runtime-1.7</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.webjars</groupId>
- <artifactId>jshint</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.webjars</groupId>
- <artifactId>less</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.webjars</groupId>
- <artifactId>emberjs</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.webjars</groupId>
- <artifactId>handlebars</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.webjars</groupId>
- <artifactId>coffee-script</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.webjars</groupId>
- <artifactId>jslint</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.webjars</groupId>
- <artifactId>json2</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.webjars</groupId>
- <artifactId>jquery</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- </dependencies>
- </plugin>
- </code>
- </pre>
- <p>The dependencies to <strong>wro4j-core</strong> and <strong>wro4j-extensions</strong> are needed by jetty, to be able to enable the filter defined below. Unfortunatly, one of the transitive dependencies of <code>wro4j-extensions</code> triggers an uggly error when running the jetty-maven-plugin. Therefore, all unneeded dependencies of <code>wro4j-extensions</code> are excluded, as a workaround for this error/bug.</p>
- <h2>jetty-web.xml</h2>
- <p>And my jetty-web.xml looks like this:</p>
- <pre class="prettyprint linenums"> <code class="xml">
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- version="2.5">
- <filter>
- <filter-name>wro</filter-name>
- <filter-class>ro.isdc.wro.http.WroFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>wro</filter-name>
- <url-pattern>*.css</url-pattern>
- </filter-mapping>
- </web-app>
- </code>
- </pre>
- <p>The filter processes any URI’s that end with <code>.css</code>. This way, the wro4j servlet-filter makes <code>base.css</code> available under any path, because for exampl <code>/base.css</code>, <code>/css/base.css</code> and <code>/foo/bar/base.css</code> all end with <code>.css</code>.</p>
- <p>This is all, that is needed to develop with dynamically reloadable compiled LESS-resources. Just fire up your browser and browse to <code>/what/you/like/base.css</code>. (But do not forget to put some LESS-files in <code>src/main/webapp/css/base/</code> first!)</p>
- <h2>Step 3: Install wro4j-maven-plugin</h2>
- <p>All that is left over to configure now, is the build-process. If you would build and deploy your webapp now, the CSS-file <code>base.css</code> would not be generated and the link to your stylesheet, that already works in our jetty-maven-plugin environment would point to a 404. Hence, we need to set up the <strong>wro4j-maven-plugin</strong>. I am using this configuration:</p>
- <pre class="prettyprint linenums"> <code class="xml">
- <plugin>
- <groupId>ro.isdc.wro4j</groupId>
- <artifactId>wro4j-maven-plugin</artifactId>
- <version>${wro4j.version}</version>
- <configuration>
- <wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
- <cssDestinationFolder>${project.build.directory}/${project.build.finalName}/css/</cssDestinationFolder>
- </configuration>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </code>
- </pre>
- <p>I connected the <code>run</code>-goal with the <code>package</code>-phase, because the statically compiled CSS-file is needed only in the final war. The <code>ConfigurableWroManagerFactory</code> tells wro4j, that it should look up further configuration options in our <code>wro.properties</code>-file, where we tell wro4j, that it should compile our LESS-resources. The <code><cssDestinationFolder></code>-tag tells wro4j, where it should put the generated CSS-file. You can adjust that to suite your needs.</p>
- <p>That’s it: now the same CSS-file, which is created on the fly by the wro4j servlet-filter when using <code>mvn jetty:run</code> and, thus, enables dynamic reloading of our LESS-resources, is generated during the build-process by the wro4j-maven-plugin.</p>
- <h2>Cleanup and further considerations</h2>
- <h3>lesscss-maven-plugin</h3>
- <p>If you already compile your LESS-resources with the lesscss-maven-plugin, you can stick with it and skip step 3. But I strongly recommend giving wro4j-maven-plugin a try, because it is a much more powerfull tool, that can speed up your final webapp even more.</p>
- <h3>Clean up your mess </h3>
- <p>With a configuration like the above one, your LESS-resources and wro4j-configuration-files will be packed into your production-war. That might be confusing later, because neither wro4j nor LESS is used in the final war. You can add the following to your <code>pom.xml</code> to exclude these files from your war for the sake of clarity:</p>
- <pre class="prettyprint linenums"> <code class="xml">
- <plugin>
- <artifactId>maven-war-plugin</artifactId>
- <configuration>
- <warSourceExcludes>
- WEB-INF/wro.*,
- less/**
- </warSourceExcludes>
- </configuration>
- </plugin>
- </code>
- </pre>
- <h3>What’s next?</h3>
- <p>We only scrached the surface, of what can be done with wro4j. Based on this configuration, you can easily enable additional features to fine-tune your final build for maximum speed. You really should take a look at the <a href="https://code.google.com/p/wro4j/wiki/AvailableProcessors" onclick="javascript:_gaq.push(['_trackEvent', 'outbound-article', 'http://code.google.com']);" title="Available Processors">list of available Processors</a>!</p>
+++ /dev/null
----
-title: Archiv - 2020
-linkTitle: 2020
-layout: year
----
+++ /dev/null
----
-categories:
- - hibernate
- - java
- - maven
-date: "2020-06-15T19:15:58+00:00"
-title: hibernate4-maven-plugin
-url: /hibernate4-maven-plugin-a-simple-plugin-for-generating-a-database-schema-from-hibernate-4-mapping-annotations/
----
- <p>
- Hibernate comes with the buildin functionality, to automatically create or update the database schema. This functionality is configured in the session-configuraton via the parameter <code>hbm2ddl.auto</code> (see <a href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-optional" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://docs.jboss.org']);">Hibernate Reference Documentation – Chapter 3.4. Optional configuration properties</a>). But doing so <a href="http://stackoverflow.com/questions/221379/hibernate-hbm2ddl-auto-update-in-production" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://stackoverflow.com']);">is not very wise</a>, because you can easily corrupt or erase your production database, if this configuration parameter slips through to your production environment.
- </p>
- <p>
- Alternatively, you can <a href="http://stackoverflow.com/questions/835961/how-to-creata-database-schema-using-hibernate" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://stackoverflow.com']);">run the tools <strong>SchemaExport</strong> or <strong>SchemaUpdate</strong> by hand</a>. But that is not very comfortable and being used to maven you will quickly long for a plugin, that does that job automatically for you, when you fire up your test cases.
- </p>
- <p>In the good old times, there was the <a href="http://mojo.codehaus.org/maven-hibernate3/hibernate3-maven-plugin/" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://mojo.codehaus.org']);">Maven Hibernate3 Plugin</a>, that does this for you. But unfortunatly, this plugin is not compatible with Hibernate 4.x. Since there does not seem to be any successor for the Maven Hibernate3 Plugin and <a href="http://www.google.de/search?q=hibernate4+maven+plugin" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://www.google.de']);">googeling</a> does not help, I decided to write up this simple plugin (inspired by these two articles I found: <a href="http://www.tikalk.com/alm/blog/schema-export-hibernate-4-and-maven" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://www.tikalk.com']);">Schema Export with Hibernate 4 and Maven</a> and <a href="http://doingenterprise.blogspot.de/2012/05/schema-generation-with-hibernate-4-jpa.html" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://doingenterprise.blogspot.de']);">Schema generation with Hibernate 4, JPA and Maven</a>).
- </p>
- <p>
- I hope, the resulting simple to use buletproof <a href="/hibernate4-maven-plugin/">hibernate4-maven-plugin</a> is usefull!
- </p>
- <p>
- <strong><a href="/hibernate4-maven-plugin/">Try it out now!</a></strong></p>
+++ /dev/null
----
-title: Archiv - 2021
-linkTitle: 2021
-layout: year
----
+++ /dev/null
----
-_edit_last: "2"
-author: kai
-categories:
- - demos
- - explained
- - java
- - kafka
- - spring
- - spring-boot
-classic-editor-remember: classic-editor
-date: "2021-02-05T17:59:38+00:00"
-guid: http://juplo.de/?p=1201
-parent_post_id: null
-post_id: "1201"
-title: 'Implementing The Outbox-Pattern With Kafka - Part 0: The example'
-url: /implementing-the-outbox-pattern-with-kafka-part-0-the-example/
-summary: In this part, a small example-project is introduced, that features a component, which has to inform another component upon every succsessfully completed operation.
----
-
-_This article is part of a Blog-Series_
-
-Based on a [very simple example-project](/implementing-the-outbox-pattern-with-kafka-part-0-the-example/)
-we will implemnt the [Outbox-Pattern](https://microservices.io/patterns/data/transactional-outbox.html) with [Kafka](https://kafka.apache.org/quickstart).
-
-- Part 0: The Example-Project
-- [Part 1: Writing In The Outbox-Table](/implementing-the-outbox-pattern-with-kafka-part-1-the-outbox-table/ "Jump to the explanation what has to be added, to enqueue messages in an outbox for successfully written transactions")
-
-## The Plan
-
-In this mini-series I will implement the [Outbox-Pattern](https://microservices.io/patterns/data/transactional-outbox.html)
-as described on Chris Richardson's fabolous website [microservices.io](https://microservices.io/).
-
-The pattern enables you, to send a message as part of a database transaction in a reliable way, effectively turining the writing of the data
-to the database and the sending of the message into an **[atomic operation](https://en.wikipedia.org/wiki/Atomicity_(database_systems))**:
-either both operations are successful or neither.
-
-The pattern is well known and implementing it with [Kafka](https://kafka.apache.org/quickstart) looks like an easy straight forward job at first glance.
-However, there are many obstacles that easily lead to an incomplete or incorrect implementation.
-In this blog-series, we will circumnavigate these obstacles together step by step.
-
-## The Example Project
-
-To illustrate our implementation, we will use a simple example-project.
-It mimics a part of the registration process for an web application:
-a (very!) simplistic service takes registration orders for new users.
-
-- Successfull registration requests will return a 201 (Created), that carries the URI, under which the data of the newly registered user can be accessed in the `Location`-header:
-
-`echo peter | http :8080/users
- HTTP/1.1 201
- Content-Length: 0
- Date: Fri, 05 Feb 2021 14:44:51 GMT
- Location: http://localhost:8080/users/peter
- `
-- Requests to registrate an already existing user will result in a 400 (Bad Request):
-
-`echo peter | http :8080/users
- HTTP/1.1 400
- Connection: close
- Content-Length: 0
- Date: Fri, 05 Feb 2021 14:44:53 GMT
- `
-- Successfully registrated users can be listed:
- `http :8080/users
- HTTP/1.1 200
- Content-Type: application/json;charset=UTF-8
- Date: Fri, 05 Feb 2021 14:53:59 GMT
- Transfer-Encoding: chunked
- [
- {
- "created": "2021-02-05T10:38:32.301",
- "loggedIn": false,
- "username": "peter"
- },
- ...
- ]
- `
-
-## The Messaging Use-Case
-
-As our messaging use-case imagine, that there has to happen several processes after a successful registration of a new user.
-This may be the generation of an invoice, some business analytics or any other lengthy process that is best carried out asynchronously.
-Hence, we have to generate an event, that informs the responsible services about new registrations.
-
-Obviously, these events should only be generated, if the registration is completed successfully.
-The event must not be fired, if the registration is rejected, because a duplicate username.
-
-On the other hand, the publication of the event must happen reliably, because otherwise, the new might not be charged for the services, we offer...
-
-## The Transaction
-
-The users are stored in a database and the creation of a new user happens in a transaction.
-A "brilliant" colleague came up with the idea, to trigger an `IncorrectResultSizeDataAccessException` to detect duplicate usernames:
-
-`User user = new User(username);
-repository.save(user);
-// Triggers an Exception, if more than one entry is found
-repository.findByUsername(username);
-`
-
-The query for the user by its names triggers an `IncorrectResultSizeDataAccessException`, if more than one entry is found.
-The uncaught exception will mark the transaction for rollback, hence, canceling the requested registration.
-The 400-response is then generated by a corresponding `ExceptionHandler`:
-
-`@ExceptionHandler
-public ResponseEntity incorrectResultSizeDataAccessException(
- IncorrectResultSizeDataAccessException e)
-{
- LOG.info("User already exists!");
- return ResponseEntity.badRequest().build();
-}
-`
-
-Please do not code this at home...
-
-But his weired implementation perfectly illustrates the requirements for our messaging use-case:
-The user is written into the database.
-But the registration is not successfully completed until the transaction is commited.
-If the transaction is rolled back, no message must be send, because no new user was registered.
-
-## Decoupling with Springs EventPublisher
-
-In the example implementation I am using an `EventPublisher` to decouple the business logic from the implementation of the messaging.
-The controller publishes an event, when a new user is registered:
-
-`publisher.publishEvent(new UserEvent(this, usernam));
-`
-
-A listener annotated with `@TransactionalEventListener` receives the events and handles the messaging:
-
-`@TransactionalEventListener
-public void onUserEvent(UserEvent event)
-{
- // Sending the message happens here...
-}
-`
-
-In non-critical use-cases, it might be sufficient to actually send the message to Kafka right here.
-Spring ensures, that the message of the listener is only called, if the transaction completes successfully.
-But in the case of a failure this naive implementation can loose messages.
-If the application crashes, after the transaction has completed, but before the message could be send, the event would be lost.
-
-In the following blog posts, we will step by step implement a solution based on the Outbox-Pattern, that can guarantee Exactly-Once semantics for the send messages.
-
-## May The Source Be With You!
-
-The complete source code of the example-project can be cloned here:
-
-- `git clone /git/demos/spring/data-jdbc`
-- `git clone https://github.com/juplo/demos-spring-data-jdbc.git`
-
-It includes a [Setup for Docker Compose](https://github.com/juplo/demos-spring-data-jdbc/blob/master/docker-compose.yml), that can be run without compiling
-the project. And a runnable [README.sh](https://github.com/juplo/demos-spring-data-jdbc/blob/master/README.sh), that compiles and run the application and illustrates the example.
--- /dev/null
+---
+title: Archiv - 2013
+linkTitle: 2013
+layout: year
+---
--- /dev/null
+---
+categories:
+ - jetty
+ - less
+ - maven
+ - wro4j
+date: "2013-12-06T10:58:17+00:00"
+title: Combining jetty-maven-plugin and wro4j-maven-plugin for Dynamic Reloading of LESS-Resources
+url: /combining-jetty-maven-plugin-and-wro4j-maven-plugin-for-dynamic-reloading-of-less-resources/
+---
+ <p>Ever searched for a simple configuration, that lets you use your <a href="http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://wiki.eclipse.org']);" title="See the documentation for mor information">jetty-maven-plugin</a> as you are used to, while working with <a href="http://www.csscss.org/" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://www.csscss.org']);" title="See LESS CSS documentation for mor informations">LESS</a> to simplify your stylesheets?</p>
+ <p>You cannot do both, use the <a href="http://www.csscss.org/#usage" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://www.csscss.org']);" title="More about the client-side usage of LESS">Client-side mode</a> of LESS to ease development and use the <a href="https://github.com/marceloverdijk/lesscss-maven-plugin" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://github.com']);" title="Homepage of the official LESS CSS maven plugin">lesscss-maven-plugin</a> to automatically compile the LESS-sources into CSS for production. That does not work, because your stylesheets must be linked in different ways if you are switching between the client-side mode – which is best for development – and the pre-compiled mode – which is best for production. For the client-side mode you need something like:</p>
+ <pre class="prettyprint linenums"> <code class="html">
+ <link rel="stylesheet" type="text/css" href="styles.css" />
+ <script src="less.js" type="text/javascript"></script>
+ </code>
+ </pre>
+ <p>While, for the pre-compiled mode, you want to link to your stylesheets as usual, with:</p>
+ <pre class="prettyprint linenums"> <code class="html">
+ <link rel="stylesheet" type="text/css" href="styles.css" />
+ </code>
+ </pre>
+ <p>While looking for a solution to this dilemma, I stumbled accross <a href="https://code.google.com/p/wro4j/" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://code.google.com']);" title="See the documentation of ths wounderfull tool">wro4j</a>. Originally intended, to speed up page-delivery by combining and minimizing multiple resources into one through the use of a servlet-filter, this tool also comes with a maven-plugin, that let you do the same offline, while compiling your webapp.</p>
+ <p>The idea is, to use the <a href="http://code.google.com/p/wro4j/wiki/MavenPlugin" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://code.google.com']);" title="See the documentation of hte wro4j-maven-plugin">wro4j-maven-plugin</a> to compile and combine your LESS-sources into CSS for production and to use the <a href="http://code.google.com/p/wro4j/wiki/Installation" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://code.google.com']);" title="See how to configure the filter">wro4j filter</a>, to dynamically deliver the compiled CSS while developing. This way, you do not have to alter your HTML-code, when switching between development and production, because you always link to the CSS-files.</p>
+ <p>So, lets get dirty!</p>
+ <h2>Step 1: Configure wro4j</h2>
+ <p>First, we configure <strong>wro4j</strong>, like as we want to use it to speed up our page. The details are explained and linked on wro4j’s <a href="http://code.google.com/p/wro4j/wiki/GettingStarted" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://code.google.com']);" title="Visit the Getting-Started-Page">Getting-Started-Page</a>. In short, we just need two files: <strong>wro.xml</strong> and <strong>wro.properties</strong>.</p>
+ <h3>wro.xml</h3>
+ <p>wro.xml tells wro4j, which resources should be combined and how the result should be named. I am using the following configuration to generate all LESS-Sources beneath <code>base/</code> into one CSS-file called <code>base.css</code>:</p>
+ <pre class="prettyprint linenums"> <code class="xml">
+ <groups xmlns="http://www.isdc.ro/wro">
+ <group name="base">
+ <css>/css/base/*.css</css>
+ </group>
+ </code>
+ </pre>
+ <p>wro4j looks for <code>/css/base/*.css</code> inside the root of the web-context, which is equal to <code>src/main/webapp</code> in a normal maven-project. There are <a href="http://code.google.com/p/wro4j/wiki/ResourceTypes" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://code.google.com']);" title="See the resource locator documentation of wro4j for more details">other ways to specifie the resources</a>, which enable you to store them elswhere. But this approach works best for our goal, because the path is understandable for both: the wro4j servlet-filter, we are configuring now for our development-environment, and the wro4j-maven-plugin, that we will configure later for build-time compilation.</p>
+ <h3>wro.properties</h3>
+ <p>wro.properties in short tells wro4j, how or if it should convert the combined sources and how it should behave. I am using the following configuration to tell wro4j, that it should convert <code>*.css</code>-sources into CSS and do that on <em>every request</em>:</p>
+ <pre class="prettyprint linenums"> <code class="properties">
+ preProcessors=less4j
+ disableCache=true
+ </code>
+ </pre>
+ <p>You can do a lot more here. There are countless <a href="http://code.google.com/p/wro4j/wiki/ConfigurationOptions" onclick="javascript:_gaq.push(['_trackEvent', 'outbound-article', 'http://code.google.com']);" title="See all configuration options">configuration options</a> to fine-tune the behaviour of wro4j. The <code>disableCache=true</code> is crucial, because we would not see the changes take effect when developing with <strong>jetty-maven-plugin</strong> later on. You can also do much more with your resources here, for example <a href="https://code.google.com/p/wro4j/wiki/AvailableProcessors" onclick="javascript:_gaq.push(['_trackEvent', 'outbound-article', 'http://code.google.com']);" title="See all available processors">minimizing</a>. But for our goal, we are now only intrested in the compilation of our LESS-sources.</p>
+ <h2>Step 2: Configure the wro4j servlet-filter</h2>
+ <p>Configuring the filter in the <strong>web.xml</strong> is easy. It is explained in wro4j’s <a href="https://code.google.com/p/wro4j/wiki/Installation" onclick="javascript:_gaq.push(['_trackEvent', 'outbound-article', 'http://code.google.com']);" title="See the installation instructions for the wro4j servlet-filter">installation-insctuctions</a>. But the trick is, that we do not want to configure that filter for the production-version of our webapp, because we want to compile the resources offline, when the webapp is build. To acchieve this, we can use the <code><overrideDescriptor></code>-Parameter of the <a href="http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin#Configuring_Your_WebApp" onclick="javascript:_gaq.push(['_trackEvent', 'outbound-article', 'http://wiki.eclipse.org']);" title="Read more about the configuration of the jetty-maven-plugin">jetty-maven-plugin</a>.</p>
+ <h2><overrideDescriptor></h2>
+ <p>This parameter lets you specify additional configuration options for the web.xml of your webapp. I am using the following configuration for my jetty-maven-plugin:</p>
+ <pre class="prettyprint linenums"> <code class="xml">
+ <plugin>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <configuration>
+ <webApp>
+ <overrideDescriptor>${project.basedir}/src/test/resources/jetty-web.xml</overrideDescriptor>
+ </webApp>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>ro.isdc.wro4j</groupId>
+ <artifactId>wro4j-core</artifactId>
+ <version>${wro4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>ro.isdc.wro4j</groupId>
+ <artifactId>wro4j-extensions</artifactId>
+ <version>${wro4j.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-pool</groupId>
+ <artifactId>commons-pool</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.google.javascript</groupId>
+ <artifactId>closure-compiler</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.github.lltyk</groupId>
+ <artifactId>dojo-shrinksafe</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.jruby</groupId>
+ <artifactId>jruby-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.jruby</groupId>
+ <artifactId>jruby-stdlib</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.jruby</groupId>
+ <artifactId>jruby-stdlib</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>me.n4u.sass</groupId>
+ <artifactId>sass-gems</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>nz.co.edmi</groupId>
+ <artifactId>bourbon-gem-jar</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.codehaus.gmaven.runtime</groupId>
+ <artifactId>gmaven-runtime-1.7</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.webjars</groupId>
+ <artifactId>jshint</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.webjars</groupId>
+ <artifactId>less</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.webjars</groupId>
+ <artifactId>emberjs</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.webjars</groupId>
+ <artifactId>handlebars</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.webjars</groupId>
+ <artifactId>coffee-script</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.webjars</groupId>
+ <artifactId>jslint</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.webjars</groupId>
+ <artifactId>json2</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.webjars</groupId>
+ <artifactId>jquery</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </code>
+ </pre>
+ <p>The dependencies to <strong>wro4j-core</strong> and <strong>wro4j-extensions</strong> are needed by jetty, to be able to enable the filter defined below. Unfortunatly, one of the transitive dependencies of <code>wro4j-extensions</code> triggers an uggly error when running the jetty-maven-plugin. Therefore, all unneeded dependencies of <code>wro4j-extensions</code> are excluded, as a workaround for this error/bug.</p>
+ <h2>jetty-web.xml</h2>
+ <p>And my jetty-web.xml looks like this:</p>
+ <pre class="prettyprint linenums"> <code class="xml">
+ <?xml version="1.0" encoding="UTF-8"?>
+ <web-app xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ version="2.5">
+ <filter>
+ <filter-name>wro</filter-name>
+ <filter-class>ro.isdc.wro.http.WroFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>wro</filter-name>
+ <url-pattern>*.css</url-pattern>
+ </filter-mapping>
+ </web-app>
+ </code>
+ </pre>
+ <p>The filter processes any URI’s that end with <code>.css</code>. This way, the wro4j servlet-filter makes <code>base.css</code> available under any path, because for exampl <code>/base.css</code>, <code>/css/base.css</code> and <code>/foo/bar/base.css</code> all end with <code>.css</code>.</p>
+ <p>This is all, that is needed to develop with dynamically reloadable compiled LESS-resources. Just fire up your browser and browse to <code>/what/you/like/base.css</code>. (But do not forget to put some LESS-files in <code>src/main/webapp/css/base/</code> first!)</p>
+ <h2>Step 3: Install wro4j-maven-plugin</h2>
+ <p>All that is left over to configure now, is the build-process. If you would build and deploy your webapp now, the CSS-file <code>base.css</code> would not be generated and the link to your stylesheet, that already works in our jetty-maven-plugin environment would point to a 404. Hence, we need to set up the <strong>wro4j-maven-plugin</strong>. I am using this configuration:</p>
+ <pre class="prettyprint linenums"> <code class="xml">
+ <plugin>
+ <groupId>ro.isdc.wro4j</groupId>
+ <artifactId>wro4j-maven-plugin</artifactId>
+ <version>${wro4j.version}</version>
+ <configuration>
+ <wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
+ <cssDestinationFolder>${project.build.directory}/${project.build.finalName}/css/</cssDestinationFolder>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </code>
+ </pre>
+ <p>I connected the <code>run</code>-goal with the <code>package</code>-phase, because the statically compiled CSS-file is needed only in the final war. The <code>ConfigurableWroManagerFactory</code> tells wro4j, that it should look up further configuration options in our <code>wro.properties</code>-file, where we tell wro4j, that it should compile our LESS-resources. The <code><cssDestinationFolder></code>-tag tells wro4j, where it should put the generated CSS-file. You can adjust that to suite your needs.</p>
+ <p>That’s it: now the same CSS-file, which is created on the fly by the wro4j servlet-filter when using <code>mvn jetty:run</code> and, thus, enables dynamic reloading of our LESS-resources, is generated during the build-process by the wro4j-maven-plugin.</p>
+ <h2>Cleanup and further considerations</h2>
+ <h3>lesscss-maven-plugin</h3>
+ <p>If you already compile your LESS-resources with the lesscss-maven-plugin, you can stick with it and skip step 3. But I strongly recommend giving wro4j-maven-plugin a try, because it is a much more powerfull tool, that can speed up your final webapp even more.</p>
+ <h3>Clean up your mess </h3>
+ <p>With a configuration like the above one, your LESS-resources and wro4j-configuration-files will be packed into your production-war. That might be confusing later, because neither wro4j nor LESS is used in the final war. You can add the following to your <code>pom.xml</code> to exclude these files from your war for the sake of clarity:</p>
+ <pre class="prettyprint linenums"> <code class="xml">
+ <plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <warSourceExcludes>
+ WEB-INF/wro.*,
+ less/**
+ </warSourceExcludes>
+ </configuration>
+ </plugin>
+ </code>
+ </pre>
+ <h3>What’s next?</h3>
+ <p>We only scrached the surface, of what can be done with wro4j. Based on this configuration, you can easily enable additional features to fine-tune your final build for maximum speed. You really should take a look at the <a href="https://code.google.com/p/wro4j/wiki/AvailableProcessors" onclick="javascript:_gaq.push(['_trackEvent', 'outbound-article', 'http://code.google.com']);" title="Available Processors">list of available Processors</a>!</p>
--- /dev/null
+---
+title: Archiv - 2020
+linkTitle: 2020
+layout: year
+---
--- /dev/null
+---
+categories:
+ - hibernate
+ - java
+ - maven
+date: "2020-06-15T19:15:58+00:00"
+title: hibernate4-maven-plugin
+url: /hibernate4-maven-plugin-a-simple-plugin-for-generating-a-database-schema-from-hibernate-4-mapping-annotations/
+---
+ <p>
+ Hibernate comes with the buildin functionality, to automatically create or update the database schema. This functionality is configured in the session-configuraton via the parameter <code>hbm2ddl.auto</code> (see <a href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-optional" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://docs.jboss.org']);">Hibernate Reference Documentation – Chapter 3.4. Optional configuration properties</a>). But doing so <a href="http://stackoverflow.com/questions/221379/hibernate-hbm2ddl-auto-update-in-production" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://stackoverflow.com']);">is not very wise</a>, because you can easily corrupt or erase your production database, if this configuration parameter slips through to your production environment.
+ </p>
+ <p>
+ Alternatively, you can <a href="http://stackoverflow.com/questions/835961/how-to-creata-database-schema-using-hibernate" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://stackoverflow.com']);">run the tools <strong>SchemaExport</strong> or <strong>SchemaUpdate</strong> by hand</a>. But that is not very comfortable and being used to maven you will quickly long for a plugin, that does that job automatically for you, when you fire up your test cases.
+ </p>
+ <p>In the good old times, there was the <a href="http://mojo.codehaus.org/maven-hibernate3/hibernate3-maven-plugin/" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://mojo.codehaus.org']);">Maven Hibernate3 Plugin</a>, that does this for you. But unfortunatly, this plugin is not compatible with Hibernate 4.x. Since there does not seem to be any successor for the Maven Hibernate3 Plugin and <a href="http://www.google.de/search?q=hibernate4+maven+plugin" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://www.google.de']);">googeling</a> does not help, I decided to write up this simple plugin (inspired by these two articles I found: <a href="http://www.tikalk.com/alm/blog/schema-export-hibernate-4-and-maven" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://www.tikalk.com']);">Schema Export with Hibernate 4 and Maven</a> and <a href="http://doingenterprise.blogspot.de/2012/05/schema-generation-with-hibernate-4-jpa.html" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://doingenterprise.blogspot.de']);">Schema generation with Hibernate 4, JPA and Maven</a>).
+ </p>
+ <p>
+ I hope, the resulting simple to use buletproof <a href="/hibernate4-maven-plugin/">hibernate4-maven-plugin</a> is usefull!
+ </p>
+ <p>
+ <strong><a href="/hibernate4-maven-plugin/">Try it out now!</a></strong></p>
--- /dev/null
+---
+title: Archiv - 2021
+linkTitle: 2021
+layout: year
+---
--- /dev/null
+---
+_edit_last: "2"
+author: kai
+categories:
+ - demos
+ - explained
+ - java
+ - kafka
+ - spring
+ - spring-boot
+classic-editor-remember: classic-editor
+date: "2021-02-05T17:59:38+00:00"
+guid: http://juplo.de/?p=1201
+parent_post_id: null
+post_id: "1201"
+title: 'Implementing The Outbox-Pattern With Kafka - Part 0: The example'
+url: /implementing-the-outbox-pattern-with-kafka-part-0-the-example/
+summary: In this part, a small example-project is introduced, that features a component, which has to inform another component upon every succsessfully completed operation.
+---
+
+_This article is part of a Blog-Series_
+
+Based on a [very simple example-project](/implementing-the-outbox-pattern-with-kafka-part-0-the-example/)
+we will implemnt the [Outbox-Pattern](https://microservices.io/patterns/data/transactional-outbox.html) with [Kafka](https://kafka.apache.org/quickstart).
+
+- Part 0: The Example-Project
+- [Part 1: Writing In The Outbox-Table](/implementing-the-outbox-pattern-with-kafka-part-1-the-outbox-table/ "Jump to the explanation what has to be added, to enqueue messages in an outbox for successfully written transactions")
+
+## The Plan
+
+In this mini-series I will implement the [Outbox-Pattern](https://microservices.io/patterns/data/transactional-outbox.html)
+as described on Chris Richardson's fabolous website [microservices.io](https://microservices.io/).
+
+The pattern enables you, to send a message as part of a database transaction in a reliable way, effectively turining the writing of the data
+to the database and the sending of the message into an **[atomic operation](https://en.wikipedia.org/wiki/Atomicity_(database_systems))**:
+either both operations are successful or neither.
+
+The pattern is well known and implementing it with [Kafka](https://kafka.apache.org/quickstart) looks like an easy straight forward job at first glance.
+However, there are many obstacles that easily lead to an incomplete or incorrect implementation.
+In this blog-series, we will circumnavigate these obstacles together step by step.
+
+## The Example Project
+
+To illustrate our implementation, we will use a simple example-project.
+It mimics a part of the registration process for an web application:
+a (very!) simplistic service takes registration orders for new users.
+
+- Successfull registration requests will return a 201 (Created), that carries the URI, under which the data of the newly registered user can be accessed in the `Location`-header:
+
+`echo peter | http :8080/users
+ HTTP/1.1 201
+ Content-Length: 0
+ Date: Fri, 05 Feb 2021 14:44:51 GMT
+ Location: http://localhost:8080/users/peter
+ `
+- Requests to registrate an already existing user will result in a 400 (Bad Request):
+
+`echo peter | http :8080/users
+ HTTP/1.1 400
+ Connection: close
+ Content-Length: 0
+ Date: Fri, 05 Feb 2021 14:44:53 GMT
+ `
+- Successfully registrated users can be listed:
+ `http :8080/users
+ HTTP/1.1 200
+ Content-Type: application/json;charset=UTF-8
+ Date: Fri, 05 Feb 2021 14:53:59 GMT
+ Transfer-Encoding: chunked
+ [
+ {
+ "created": "2021-02-05T10:38:32.301",
+ "loggedIn": false,
+ "username": "peter"
+ },
+ ...
+ ]
+ `
+
+## The Messaging Use-Case
+
+As our messaging use-case imagine, that there has to happen several processes after a successful registration of a new user.
+This may be the generation of an invoice, some business analytics or any other lengthy process that is best carried out asynchronously.
+Hence, we have to generate an event, that informs the responsible services about new registrations.
+
+Obviously, these events should only be generated, if the registration is completed successfully.
+The event must not be fired, if the registration is rejected, because a duplicate username.
+
+On the other hand, the publication of the event must happen reliably, because otherwise, the new might not be charged for the services, we offer...
+
+## The Transaction
+
+The users are stored in a database and the creation of a new user happens in a transaction.
+A "brilliant" colleague came up with the idea, to trigger an `IncorrectResultSizeDataAccessException` to detect duplicate usernames:
+
+`User user = new User(username);
+repository.save(user);
+// Triggers an Exception, if more than one entry is found
+repository.findByUsername(username);
+`
+
+The query for the user by its names triggers an `IncorrectResultSizeDataAccessException`, if more than one entry is found.
+The uncaught exception will mark the transaction for rollback, hence, canceling the requested registration.
+The 400-response is then generated by a corresponding `ExceptionHandler`:
+
+`@ExceptionHandler
+public ResponseEntity incorrectResultSizeDataAccessException(
+ IncorrectResultSizeDataAccessException e)
+{
+ LOG.info("User already exists!");
+ return ResponseEntity.badRequest().build();
+}
+`
+
+Please do not code this at home...
+
+But his weired implementation perfectly illustrates the requirements for our messaging use-case:
+The user is written into the database.
+But the registration is not successfully completed until the transaction is commited.
+If the transaction is rolled back, no message must be send, because no new user was registered.
+
+## Decoupling with Springs EventPublisher
+
+In the example implementation I am using an `EventPublisher` to decouple the business logic from the implementation of the messaging.
+The controller publishes an event, when a new user is registered:
+
+`publisher.publishEvent(new UserEvent(this, usernam));
+`
+
+A listener annotated with `@TransactionalEventListener` receives the events and handles the messaging:
+
+`@TransactionalEventListener
+public void onUserEvent(UserEvent event)
+{
+ // Sending the message happens here...
+}
+`
+
+In non-critical use-cases, it might be sufficient to actually send the message to Kafka right here.
+Spring ensures, that the message of the listener is only called, if the transaction completes successfully.
+But in the case of a failure this naive implementation can loose messages.
+If the application crashes, after the transaction has completed, but before the message could be send, the event would be lost.
+
+In the following blog posts, we will step by step implement a solution based on the Outbox-Pattern, that can guarantee Exactly-Once semantics for the send messages.
+
+## May The Source Be With You!
+
+The complete source code of the example-project can be cloned here:
+
+- `git clone /git/demos/spring/data-jdbc`
+- `git clone https://github.com/juplo/demos-spring-data-jdbc.git`
+
+It includes a [Setup for Docker Compose](https://github.com/juplo/demos-spring-data-jdbc/blob/master/docker-compose.yml), that can be run without compiling
+the project. And a runnable [README.sh](https://github.com/juplo/demos-spring-data-jdbc/blob/master/README.sh), that compiles and run the application and illustrates the example.
--- /dev/null
+{{ define "content" }}
+ {{ .Content }}
+
+ {{ with .Date }}
+ <div>
+ <em>Written:</em>
+ <time datetime="{{ . | time.Format "2006-01-02T15:04:05-07:00" }}">{{ . | time.Format ":date_long" }}</time>
+ </div>
+ {{ end }}
+ {{ if .Lastmod.After .Date }}
+ <div>
+ <em>LastModified:</em>
+ <time datetime="{{ .Lastmod | time.Format "2006-01-02T15:04:05-07:00" }}">{{ .Lastmod | time.Format ":date_long" }}</time>
+ </div>
+ {{ end }}
+{{ end }}
+{{ define "menu" }}{{ partial "menu/blog.html" (dict "page" .) }}{{ end }}
+{{ define "marginalcontent" }}
+ {{ partial "terms.html" . }}
+{{ end }}
--- /dev/null
+{{- define "title" }}
+ <h1>
+ {{- with .OutputFormats.Get "rss" }}
+ <a href="{{ .RelPermalink }}" title="RSS" aria-label="RSS">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="4"
+ stroke-linecap="round" stroke-linejoin="round" height="23">
+ <path d="M4 11a9 9 0 0 1 9 9" />
+ <path d="M4 4a16 16 0 0 1 16 16" />
+ <circle cx="5" cy="19" r="1" />
+ </svg>
+ Archive of all Blog-Articles
+ </a>
+ </h1>
+ {{- end }}
+{{- end }}{{/* end title */}}
+
+{{- define "content" }}
+{{- range .RegularPagesRecursive }}
+ <div class="archive-entry">
+ <h3 class="archive-entry-title entry-hint-parent">
+ <a class="entry-link" aria-label="post link to {{ .Title | plainify }}" href="{{ .Permalink }}">{{- .Title | markdownify }}</a>
+ {{- if .Draft }}
+ <span class="entry-hint" title="Draft">
+ <svg xmlns="http://www.w3.org/2000/svg" height="15" viewBox="0 -960 960 960" fill="currentColor">
+ <path
+ d="M160-410v-60h300v60H160Zm0-165v-60h470v60H160Zm0-165v-60h470v60H160Zm360 580v-123l221-220q9-9 20-13t22-4q12 0 23 4.5t20 13.5l37 37q9 9 13 20t4 22q0 11-4.5 22.5T862.09-380L643-160H520Zm300-263-37-37 37 37ZM580-220h38l121-122-18-19-19-18-122 121v38Zm141-141-19-18 37 37-18-19Z" />
+ </svg>
+ </span>
+ {{- end }}
+ </h3>
+ <div class="archive-meta">
+ {{- partial "post_meta.html" . -}}
+ </div>
+ </div>
+{{- end }}
+{{- end }}{{/* end main */}}
--- /dev/null
+{{- define "title" }}
+ <h1>
+ {{ .Title }}
+ {{- if (.Param "ShowRssButtonInSectionTermList") }}
+ {{- $rss := (.OutputFormats.Get "rss") }}
+ {{- if (eq .Kind `page`) }}
+ {{- $rss = (.Parent.OutputFormats.Get "rss") }}
+ {{- end }}
+ {{- with $rss }}
+ <a href="{{ .RelPermalink }}" title="RSS" aria-label="RSS">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
+ stroke-linecap="round" stroke-linejoin="round" height="23">
+ <path d="M4 11a9 9 0 0 1 9 9" />
+ <path d="M4 4a16 16 0 0 1 16 16" />
+ <circle cx="5" cy="19" r="1" />
+ </svg>
+ </a>
+ {{- end }}
+ {{- end }}
+ </h1>
+ {{- if .Description }}
+ <div class="post-description">
+ {{ .Description }}
+ </div>
+ {{- end }}
+{{- end }}{{/* end title */}}
+
+{{- define "content" }}
+{{- range .Pages }}
+<div class="archive-entry">
+ <h3 class="archive-entry-title entry-hint-parent">
+ <a class="entry-link" aria-label="post link to {{ .Title | plainify }}" href="{{ .Permalink }}">{{- .Title | markdownify }}</a>
+ {{- if .Draft }}
+ <span class="entry-hint" title="Draft">
+ <svg xmlns="http://www.w3.org/2000/svg" height="15" viewBox="0 -960 960 960" fill="currentColor">
+ <path
+ d="M160-410v-60h300v60H160Zm0-165v-60h470v60H160Zm0-165v-60h470v60H160Zm360 580v-123l221-220q9-9 20-13t22-4q12 0 23 4.5t20 13.5l37 37q9 9 13 20t4 22q0 11-4.5 22.5T862.09-380L643-160H520Zm300-263-37-37 37 37ZM580-220h38l121-122-18-19-19-18-122 121v38Zm141-141-19-18 37 37-18-19Z" />
+ </svg>
+ </span>
+ {{- end }}
+ </h3>
+ <div class="archive-meta">
+ {{- partial "post_meta.html" . -}}
+ </div>
+</div>
+{{- end }}
+{{- end }}{{/* end main */}}
+
+{{- define "menu" }}
+{{- partial "menu/blog.html" (dict "page" .) }}
+{{- end }}{{/* end menu */}}
+++ /dev/null
-{{ define "content" }}
- {{ .Content }}
-
- {{ with .Date }}
- <div>
- <em>Written:</em>
- <time datetime="{{ . | time.Format "2006-01-02T15:04:05-07:00" }}">{{ . | time.Format ":date_long" }}</time>
- </div>
- {{ end }}
- {{ if .Lastmod.After .Date }}
- <div>
- <em>LastModified:</em>
- <time datetime="{{ .Lastmod | time.Format "2006-01-02T15:04:05-07:00" }}">{{ .Lastmod | time.Format ":date_long" }}</time>
- </div>
- {{ end }}
-{{ end }}
-{{ define "menu" }}{{ partial "menu/blog.html" (dict "page" .) }}{{ end }}
-{{ define "marginalcontent" }}
- {{ partial "terms.html" . }}
-{{ end }}
+++ /dev/null
-{{- define "title" }}
- <h1>
- {{ .Title }}
- {{- if (.Param "ShowRssButtonInSectionTermList") }}
- {{- $rss := (.OutputFormats.Get "rss") }}
- {{- if (eq .Kind `page`) }}
- {{- $rss = (.Parent.OutputFormats.Get "rss") }}
- {{- end }}
- {{- with $rss }}
- <a href="{{ .RelPermalink }}" title="RSS" aria-label="RSS">
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
- stroke-linecap="round" stroke-linejoin="round" height="23">
- <path d="M4 11a9 9 0 0 1 9 9" />
- <path d="M4 4a16 16 0 0 1 16 16" />
- <circle cx="5" cy="19" r="1" />
- </svg>
- </a>
- {{- end }}
- {{- end }}
- </h1>
- {{- if .Description }}
- <div class="post-description">
- {{ .Description }}
- </div>
- {{- end }}
-{{- end }}{{/* end title */}}
-
-{{- define "content" }}
-{{- range .Pages }}
-<div class="archive-entry">
- <h3 class="archive-entry-title entry-hint-parent">
- <a class="entry-link" aria-label="post link to {{ .Title | plainify }}" href="{{ .Permalink }}">{{- .Title | markdownify }}</a>
- {{- if .Draft }}
- <span class="entry-hint" title="Draft">
- <svg xmlns="http://www.w3.org/2000/svg" height="15" viewBox="0 -960 960 960" fill="currentColor">
- <path
- d="M160-410v-60h300v60H160Zm0-165v-60h470v60H160Zm0-165v-60h470v60H160Zm360 580v-123l221-220q9-9 20-13t22-4q12 0 23 4.5t20 13.5l37 37q9 9 13 20t4 22q0 11-4.5 22.5T862.09-380L643-160H520Zm300-263-37-37 37 37ZM580-220h38l121-122-18-19-19-18-122 121v38Zm141-141-19-18 37 37-18-19Z" />
- </svg>
- </span>
- {{- end }}
- </h3>
- <div class="archive-meta">
- {{- partial "post_meta.html" . -}}
- </div>
-</div>
-{{- end }}
-{{- end }}{{/* end main */}}
-
-{{- define "menu" }}
-{{- partial "menu/blog.html" (dict "page" .) }}
-{{- end }}{{/* end menu */}}
--- /dev/null
+{{- define "title" }}
+ <h1>
+ {{- with .OutputFormats.Get "rss" }}
+ <a href="{{ .RelPermalink }}" title="RSS" aria-label="RSS">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="4"
+ stroke-linecap="round" stroke-linejoin="round" height="23">
+ <path d="M4 11a9 9 0 0 1 9 9" />
+ <path d="M4 4a16 16 0 0 1 16 16" />
+ <circle cx="5" cy="19" r="1" />
+ </svg>
+ Archive of all Blog-Articles
+ </a>
+ </h1>
+ {{- end }}
+{{- end }}{{/* end title */}}
+
+{{- define "content" }}
+{{- range .RegularPagesRecursive }}
+ <div class="archive-entry">
+ <h3 class="archive-entry-title entry-hint-parent">
+ <a class="entry-link" aria-label="post link to {{ .Title | plainify }}" href="{{ .Permalink }}">{{- .Title | markdownify }}</a>
+ {{- if .Draft }}
+ <span class="entry-hint" title="Draft">
+ <svg xmlns="http://www.w3.org/2000/svg" height="15" viewBox="0 -960 960 960" fill="currentColor">
+ <path
+ d="M160-410v-60h300v60H160Zm0-165v-60h470v60H160Zm0-165v-60h470v60H160Zm360 580v-123l221-220q9-9 20-13t22-4q12 0 23 4.5t20 13.5l37 37q9 9 13 20t4 22q0 11-4.5 22.5T862.09-380L643-160H520Zm300-263-37-37 37 37ZM580-220h38l121-122-18-19-19-18-122 121v38Zm141-141-19-18 37 37-18-19Z" />
+ </svg>
+ </span>
+ {{- end }}
+ </h3>
+ <div class="archive-meta">
+ {{- partial "post_meta.html" . -}}
+ </div>
+ </div>
+{{- end }}
+{{- end }}{{/* end main */}}
--- /dev/null
+{{- define "title" }}
+ <h1>
+ {{- with .OutputFormats.Get "rss" }}
+ <a href="{{ .RelPermalink }}" title="RSS" aria-label="RSS">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="4"
+ stroke-linecap="round" stroke-linejoin="round" height="23">
+ <path d="M4 11a9 9 0 0 1 9 9" />
+ <path d="M4 4a16 16 0 0 1 16 16" />
+ <circle cx="5" cy="19" r="1" />
+ </svg>
+ Archive of all Blog-Articles
+ </a>
+ </h1>
+ {{- end }}
+{{- end }}{{/* end title */}}
+
+{{- define "content" }}
+{{- range .RegularPagesRecursive }}
+ <div class="archive-entry">
+ <h3 class="archive-entry-title entry-hint-parent">
+ <a class="entry-link" aria-label="post link to {{ .Title | plainify }}" href="{{ .Permalink }}">{{- .Title | markdownify }}</a>
+ {{- if .Draft }}
+ <span class="entry-hint" title="Draft">
+ <svg xmlns="http://www.w3.org/2000/svg" height="15" viewBox="0 -960 960 960" fill="currentColor">
+ <path
+ d="M160-410v-60h300v60H160Zm0-165v-60h470v60H160Zm0-165v-60h470v60H160Zm360 580v-123l221-220q9-9 20-13t22-4q12 0 23 4.5t20 13.5l37 37q9 9 13 20t4 22q0 11-4.5 22.5T862.09-380L643-160H520Zm300-263-37-37 37 37ZM580-220h38l121-122-18-19-19-18-122 121v38Zm141-141-19-18 37 37-18-19Z" />
+ </svg>
+ </span>
+ {{- end }}
+ </h3>
+ <div class="archive-meta">
+ {{- partial "post_meta.html" . -}}
+ </div>
+ </div>
+{{- end }}
+{{- end }}{{/* end main */}}
--- /dev/null
+{{- define "title" }}
+ <h1>
+ {{- with .OutputFormats.Get "rss" }}
+ <a href="{{ .RelPermalink }}" title="RSS" aria-label="RSS">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="4"
+ stroke-linecap="round" stroke-linejoin="round" height="23">
+ <path d="M4 11a9 9 0 0 1 9 9" />
+ <path d="M4 4a16 16 0 0 1 16 16" />
+ <circle cx="5" cy="19" r="1" />
+ </svg>
+ Archive of all Blog-Articles
+ </a>
+ </h1>
+ {{- end }}
+{{- end }}{{/* end title */}}
+
+{{- define "content" }}
+{{- range .RegularPagesRecursive }}
+ <div class="archive-entry">
+ <h3 class="archive-entry-title entry-hint-parent">
+ <a class="entry-link" aria-label="post link to {{ .Title | plainify }}" href="{{ .Permalink }}">{{- .Title | markdownify }}</a>
+ {{- if .Draft }}
+ <span class="entry-hint" title="Draft">
+ <svg xmlns="http://www.w3.org/2000/svg" height="15" viewBox="0 -960 960 960" fill="currentColor">
+ <path
+ d="M160-410v-60h300v60H160Zm0-165v-60h470v60H160Zm0-165v-60h470v60H160Zm360 580v-123l221-220q9-9 20-13t22-4q12 0 23 4.5t20 13.5l37 37q9 9 13 20t4 22q0 11-4.5 22.5T862.09-380L643-160H520Zm300-263-37-37 37 37ZM580-220h38l121-122-18-19-19-18-122 121v38Zm141-141-19-18 37 37-18-19Z" />
+ </svg>
+ </span>
+ {{- end }}
+ </h3>
+ <div class="archive-meta">
+ {{- partial "post_meta.html" . -}}
+ </div>
+ </div>
+{{- end }}
+{{- end }}{{/* end main */}}
--- /dev/null
+{{- define "title" }}
+ <h1>
+ {{- with .OutputFormats.Get "rss" }}
+ <a href="{{ .RelPermalink }}" title="RSS" aria-label="RSS">
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="4"
+ stroke-linecap="round" stroke-linejoin="round" height="23">
+ <path d="M4 11a9 9 0 0 1 9 9" />
+ <path d="M4 4a16 16 0 0 1 16 16" />
+ <circle cx="5" cy="19" r="1" />
+ </svg>
+ Archive of all Blog-Articles
+ </a>
+ </h1>
+ {{- end }}
+{{- end }}{{/* end title */}}
+
+{{- define "content" }}
+{{- range .RegularPagesRecursive }}
+ <div class="archive-entry">
+ <h3 class="archive-entry-title entry-hint-parent">
+ <a class="entry-link" aria-label="post link to {{ .Title | plainify }}" href="{{ .Permalink }}">{{- .Title | markdownify }}</a>
+ {{- if .Draft }}
+ <span class="entry-hint" title="Draft">
+ <svg xmlns="http://www.w3.org/2000/svg" height="15" viewBox="0 -960 960 960" fill="currentColor">
+ <path
+ d="M160-410v-60h300v60H160Zm0-165v-60h470v60H160Zm0-165v-60h470v60H160Zm360 580v-123l221-220q9-9 20-13t22-4q12 0 23 4.5t20 13.5l37 37q9 9 13 20t4 22q0 11-4.5 22.5T862.09-380L643-160H520Zm300-263-37-37 37 37ZM580-220h38l121-122-18-19-19-18-122 121v38Zm141-141-19-18 37 37-18-19Z" />
+ </svg>
+ </span>
+ {{- end }}
+ </h3>
+ <div class="archive-meta">
+ {{- partial "post_meta.html" . -}}
+ </div>
+ </div>
+{{- end }}
+{{- end }}{{/* end main */}}