<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: mimiz33</title>
    <description>The latest articles on DEV Community by mimiz33 (@mimiz).</description>
    <link>https://dev.to/mimiz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F425897%2F387c9e54-b334-485f-b49e-0ff5c15b924d.jpeg</url>
      <title>DEV Community: mimiz33</title>
      <link>https://dev.to/mimiz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mimiz"/>
    <language>en</language>
    <item>
      <title>How To Run Spring Cloud Data Flow with Azure Event Hub as a Binder</title>
      <dc:creator>mimiz33</dc:creator>
      <pubDate>Sun, 09 Aug 2020 14:19:24 +0000</pubDate>
      <link>https://dev.to/mimiz/how-to-run-spring-cloud-data-flow-with-azure-event-hub-as-a-binder-20pp</link>
      <guid>https://dev.to/mimiz/how-to-run-spring-cloud-data-flow-with-azure-event-hub-as-a-binder-20pp</guid>
      <description>&lt;p&gt;Recently I had to work with &lt;a href="https://dataflow.spring.io/"&gt;Spring Cloud Data Flow&lt;/a&gt;, which is a microservice streaming and batch platform based on Cloud Foundry and Kubernetes. As I am using it with Kubernetes, I will not talk about Cloud Foundry. &lt;/p&gt;

&lt;p&gt;I am using Azure Kubernetes Service, and I would like to use Azure Event Hubs as &lt;a href="https://dataflow.spring.io/"&gt;Spring Cloud Data Flow&lt;/a&gt; Binder.&lt;/p&gt;

&lt;p&gt;We (me and my teammates) spent a lot of time reading documentation (&lt;a href="https://dataflow.spring.io/"&gt;Spring Cloud Data Flow&lt;/a&gt; configuration and also &lt;a href="https://spring.io/projects/spring-cloud-stream"&gt;Spring Cloud Stream&lt;/a&gt; configurations ) and we've found that we should define binders configuration when deploying the stream, and not at a server level.&lt;/p&gt;

&lt;p&gt;Imagine the following stream:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;stream create &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s1"&gt;'uppercase'&lt;/span&gt; &lt;span class="nt"&gt;--definition&lt;/span&gt; &lt;span class="s1"&gt;'http | transform --expression=payload.toUpperCase() | log'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This stream will get some data from an &lt;strong&gt;http&lt;/strong&gt; endpoint, then the data will be &lt;strong&gt;transformed&lt;/strong&gt; to uppercase then &lt;strong&gt;logged&lt;/strong&gt;, an easy stream, good for make some tests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Each application &lt;em&gt;(http/transform/log)&lt;/em&gt; need to have a dependency to the specific binder &lt;strong&gt;(and only one)&lt;/strong&gt;, it means that if you want to use the same application with different binders you will have to build different versions.&lt;/p&gt;

&lt;p&gt;When deploying the stream, you can pass some configuration properties to each application :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;stream deploy uppercase &lt;span class="nt"&gt;--properties&lt;/span&gt; &lt;span class="s2"&gt;"deployer.http.kubernetes.createNodePort=true"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This for example will tell the "&lt;strong&gt;deployer&lt;/strong&gt;" (&lt;em&gt;ie:&lt;/em&gt; Skipper) to create a &lt;strong&gt;NodePort&lt;/strong&gt; service pointing to the &lt;strong&gt;http&lt;/strong&gt; application in Kubernetes (so it will be possible to send a message from outside the cluster)&lt;/p&gt;

&lt;p&gt;We want that when the application is created by &lt;a href="https://dataflow.spring.io/"&gt;Spring Cloud Data Flow&lt;/a&gt;, it passes some properties directly to the applications (and all applications), for example, we do not want to define the credential information for each application when deploying the stream, it may be injected by &lt;a href="https://dataflow.spring.io/"&gt;Spring Cloud Data Flow&lt;/a&gt; itself.&lt;/p&gt;

&lt;p&gt;In order to do that we will have to edit the &lt;strong&gt;ConfigMap&lt;/strong&gt; used for the Dataflow Server, to define a set of binders (with all needed configuration), and then it will be possible to reference those binders when deploying our stream.&lt;/p&gt;

&lt;p&gt;Here is the new &lt;strong&gt;ConfigMap&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ConfigMap&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;scdf-server&lt;/span&gt;
  &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;scdf-server&lt;/span&gt;
&lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="s"&gt;application.yaml&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|-&lt;/span&gt;
    &lt;span class="s"&gt;spring:&lt;/span&gt;
      &lt;span class="s"&gt;cloud:&lt;/span&gt;
        &lt;span class="s"&gt;dataflow:&lt;/span&gt;
          &lt;span class="s"&gt;applicationProperties:&lt;/span&gt;
            &lt;span class="s"&gt;stream:&lt;/span&gt;
              &lt;span class="s"&gt;spring:&lt;/span&gt;
                &lt;span class="s"&gt;cloud:&lt;/span&gt;
                  &lt;span class="s"&gt;azure:&lt;/span&gt;
                    &lt;span class="s"&gt;eventhub:&lt;/span&gt;
                      &lt;span class="s"&gt;# this is the "default" binders as it is needed by&lt;/span&gt;
                      &lt;span class="s"&gt;# The Azure Event Hub Binder&lt;/span&gt;
                      &lt;span class="s"&gt;connection-string: BINDER_ENDPOINT_CONNECTION_STRING&lt;/span&gt;
                      &lt;span class="s"&gt;checkpoint-storage-account: BINDER_STORAGE_ACCOUNT&lt;/span&gt;
                      &lt;span class="s"&gt;checkpoint-access-key: BINDER_STORAGE_ACCOUNT_ACCESS_KEY&lt;/span&gt;
                      &lt;span class="s"&gt;checkpoint-container: BINDER_STORAGE_ACCOUNT_CONTAINER&lt;/span&gt;
                  &lt;span class="s"&gt;stream:&lt;/span&gt;
                    &lt;span class="s"&gt;# create other binders if needed&lt;/span&gt;
                    &lt;span class="s"&gt;binders:&lt;/span&gt;
                      &lt;span class="s"&gt;binder-one:&lt;/span&gt;
                        &lt;span class="s"&gt;type: eventhub&lt;/span&gt;
                        &lt;span class="s"&gt;defaultCandidate: false&lt;/span&gt;
                        &lt;span class="s"&gt;environment:&lt;/span&gt;
                          &lt;span class="s"&gt;spring:&lt;/span&gt;
                            &lt;span class="s"&gt;cloud:&lt;/span&gt;
                              &lt;span class="s"&gt;azure:&lt;/span&gt;
                                &lt;span class="s"&gt;eventhub:&lt;/span&gt;
                                  &lt;span class="s"&gt;connection-string: BINDER_ONE_ENDPOINT_CONNECTION_STRING&lt;/span&gt;
                                  &lt;span class="s"&gt;checkpoint-storage-account: BINDER_ONE_STORAGE_ACCOUNT&lt;/span&gt;
                                  &lt;span class="s"&gt;checkpoint-access-key: BINDER_ONE_STORAGE_ACCOUNT_ACCESS_KEY&lt;/span&gt;
                                  &lt;span class="s"&gt;checkpoint-container: BINDER_ONE_STORAGE_ACCOUNT_CONTAINER&lt;/span&gt;
                       &lt;span class="s"&gt;binder-two:&lt;/span&gt;
                         &lt;span class="s"&gt;type: eventhub&lt;/span&gt;
                         &lt;span class="s"&gt;defaultCandidate: false&lt;/span&gt;
                         &lt;span class="s"&gt;environment:&lt;/span&gt;
                           &lt;span class="s"&gt;spring:&lt;/span&gt;
                             &lt;span class="s"&gt;cloud:&lt;/span&gt;
                               &lt;span class="s"&gt;azure:&lt;/span&gt;
                                 &lt;span class="s"&gt;eventhub:&lt;/span&gt;
                                   &lt;span class="s"&gt;connection-string: BINDER_TWO_ENDPOINT_CONNECTION_STRING&lt;/span&gt;
                                   &lt;span class="s"&gt;checkpoint-storage-account: BINDER_TWO_STORAGE_ACCOUNT&lt;/span&gt;
                                   &lt;span class="s"&gt;checkpoint-access-key: BINDER_TWO_STORAGE_ACCOUNT_ACCESS_KEY&lt;/span&gt;
                                   &lt;span class="s"&gt;checkpoint-container: BINDER_TWO_STORAGE_ACCOUNT_CONTAINER&lt;/span&gt;
      &lt;span class="s"&gt;datasource:&lt;/span&gt;
        &lt;span class="s"&gt;url: jdbc:sqlserver:&lt;/span&gt;
        &lt;span class="s"&gt;username: your_username&lt;/span&gt;
        &lt;span class="s"&gt;password: your_password&lt;/span&gt;
        &lt;span class="s"&gt;driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver&lt;/span&gt;
        &lt;span class="s"&gt;testOnBorrow: true&lt;/span&gt;
        &lt;span class="s"&gt;validationQuery: "SELECT 1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then now when deploying the stream you can use the following command :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;stream deploy uppercase &lt;span class="nt"&gt;--properties&lt;/span&gt; &lt;span class="s2"&gt;"deployer.http.kubernetes.createNodePort=true,app.http.spring.cloud.stream.bindings.output.binder=binder-one,app.transform.spring.cloud.stream.bindings.input.binder=binder-one,app.transform.spring.cloud.stream.bindings.output.binder=binder-two,app.log.spring.cloud.stream.bindings.input.binder=binder-two"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is it! &lt;/p&gt;

&lt;p&gt;I hope this post helped you.&lt;br&gt;
Note, I originally posted this article on medium : &lt;a href="https://medium.com/@rgoyard/how-to-run-spring-cloud-data-flow-with-azure-event-hub-as-a-binder-f5e888d0719"&gt;https://medium.com/@rgoyard/how-to-run-spring-cloud-data-flow-with-azure-event-hub-as-a-binder-f5e888d0719&lt;/a&gt;&lt;/p&gt;

</description>
      <category>azure</category>
      <category>java</category>
      <category>springclouddataflow</category>
      <category>azureeventhubs</category>
    </item>
  </channel>
</rss>
