<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ceyhun ÜNLÜ on Medium]]></title>
        <description><![CDATA[Stories by Ceyhun ÜNLÜ on Medium]]></description>
        <link>https://medium.com/@ceyhununlu?source=rss-4fb2bfef3455------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6N4kJUE6YTBOYm_8mmA1YQ@2x.jpeg</url>
            <title>Stories by Ceyhun ÜNLÜ on Medium</title>
            <link>https://medium.com/@ceyhununlu?source=rss-4fb2bfef3455------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 08:29:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ceyhununlu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Publish and Consume Messages with MassTransit and RabbitMQ on .Net 6]]></title>
            <link>https://medium.com/multinetinventiv/publish-and-consume-messages-with-masstransit-and-rabbitmq-on-net-6-6118377bfedb?source=rss-4fb2bfef3455------2</link>
            <guid isPermaLink="false">https://medium.com/p/6118377bfedb</guid>
            <category><![CDATA[mass-transit]]></category>
            <category><![CDATA[rabbitmq]]></category>
            <category><![CDATA[message-broker]]></category>
            <category><![CDATA[net6]]></category>
            <category><![CDATA[message-bus]]></category>
            <dc:creator><![CDATA[Ceyhun ÜNLÜ]]></dc:creator>
            <pubDate>Tue, 03 May 2022 12:09:21 GMT</pubDate>
            <atom:updated>2022-05-03T12:24:20.028Z</atom:updated>
            <content:encoded><![CDATA[<h3>Publish and Consume Messages with MassTransit and RabbitMQ in .Net 6</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*AHhw4AnsIQR5N3tERIeWFQ.png" /></figure><p>In this article, we are going to explain about message broker systems and introduce an open source message bus, called as MassTransit. After the introduction, there will be mini tutorial project with .Net 6.</p><h3>Message Broker</h3><p>A message broker is an application that exchanges data between applications, systems, and services, regardless of apps were written in different languages or different environments.</p><p>Especially in large systems, when the data flow is very high, the processes must be placed in a certain order because the server capabilities are limited. In large systems, modular and independent applications enable communication with messaging using predetermined standard message. Bottlenecks can occur in communications with “brokerless” architecture. Application communications should not run in a way that blocks each other. Message brokers roles in middle layer can overcome this with queued requests. There are many message brokers which are Azure Service Bus, Apache Kafka and Rabbit Mq are one of the most popular ones.</p><h3>RabbitMQ</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hi6hhFqy6TJO-qy8qhyp8A.png" /></figure><p>RabbitMQ is a messaging broker for messaging. RabbitMQ enables asynchronous processing. It gives applications a common platform to send and receive messages, and store messages until consumers is ready. RabbitMQ simply stores messages and passes them to consumers when ready.</p><h3>MassTransit</h3><p>MassTransit is a lightweight service bus for building distributed .NET applications. The main goal is to provide a consistent, .NET friendly abstraction over the message transport (whether it is RabbitMQ, Azure Service Bus, etc.)</p><p>There are a few fundamental concepts we should cover first:</p><p><strong>Service Bus:</strong> is the term given to the type of application that handles the movement of messages.</p><p><strong>Transports </strong>are the different types of message brokers MassTransit works with.</p><p><strong>Message </strong>is a contract, defined <em>code first </em>by creating a .NET class or an interface.</p><p>There some of advantages of choosing to use MassTransit instead of working with the native message broker library. First of all, it helps developer to work with multiple message brokers without extra implementation because of abstracting the underlying of message broker logic so that message brokers can be used simultaneously in an environment or different in each environment. In addition to this, MassTransit provides built-in solutions for exception handling, retries, circuit breaker, distributed transaction management, routing, consumer lifecycle management, monitoring and so on. Developers don’t need to implement all of these features. It saves time and helps developer to focus on the needs of their projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*C0lDfQAYRNZEFV7fZa_jZw.jpeg" /></figure><p>Now that we have an understanding of what MassTransit is and why we would use it, let’s see how we can use it along with RabbitMQ in .Net 6.</p><p>Example scenario is that user wants to notify via calling an api. We are going to develop notifier project which has two apps, a producer api and a consumer console app. Both apps are going to be created with default Visual Studio 2022 templates. Project is going to be using docker compose as orchestrator. Both apps dockerized and rabbitmq runs in docker.</p><h3>Producer App</h3><p>Producer app will produce ‘notification-created’ events to RabbitMQ. In order to produce this event, api will provide user to make HTTP request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*01xXjhiIGQfu4ukp3tINIQ.png" /></figure><p>We created producer app with default settings of related Visual Studio 2022 template. Now we need to create a message contract to use it during exchange of data between producer and consumer app. Followings will be used in this purpose.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60435f9aeed9db4b87a49ac14e8821f6/href">https://medium.com/media/60435f9aeed9db4b87a49ac14e8821f6/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3622d152a8b34e9fe9caedfe26bc82b/href">https://medium.com/media/e3622d152a8b34e9fe9caedfe26bc82b/href</a></iframe><p>There are different kinds of practices to connect queues to producers and consumers. One of them is to put message contract classes on a class library project and add its reference to related apps because MassTransit includes the namespace for message contracts so that we created the shared library project and set the dependencies.</p><p>Now, we are going to set up Program.cs in order to connect app with RabbitMQ via MassTransit</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9974bb1cc3fbaa8a4fd9248235ae64c/href">https://medium.com/media/c9974bb1cc3fbaa8a4fd9248235ae64c/href</a></iframe><p>We will configure our RabbitMQ later but in this place we put its name, ‘rabbitmq’. Configurations and credential settings can be configured here. MassTransit provides kinds of configuration. <a href="https://masstransit-project.com/usage/configuration.html#configuration-2">click for more details</a></p><p>Final part for the producer app is the user interaction part. To provide that, we are going to implement notify api with the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d02311509c01f1bcee5c71c71a46dab7/href">https://medium.com/media/d02311509c01f1bcee5c71c71a46dab7/href</a></iframe><p>Our producer app publishes an INotificationCreated event when a user makes a request. In order to do that, MassTransit presents <strong>IPublishEndPoint</strong>. we can publish our specific event with <strong>Publish&lt;T&gt;(obj)</strong> method. We can define an anonymous type, ensuring we use the same property names of INotificationCreated.</p><h3>Consumer App</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*hgyPzTBIHJMspuLRduev8w.png" /></figure><p>In order to process INotificationCreated event, we need to implement its consumer. MassTransit provides <strong>IConsumer&lt;T&gt; </strong>class to consume messages from related queues so that We implemented NotificationCreatedConsumer. INotificationCreated message gets serialized and written in the console.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cbc746273bc161eb704e052b1877b31/href">https://medium.com/media/7cbc746273bc161eb704e052b1877b31/href</a></iframe><p>Now, we are going to set up Program.cs in order to connect app with RabbitMQ via MassTransit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96c7bd80d0e2365e2340bf9c29378283/href">https://medium.com/media/96c7bd80d0e2365e2340bf9c29378283/href</a></iframe><p>We registered the consumer by loading executing assembly and giving it to the <strong>AddConsumers()</strong> method. In order to configure RabbitMQ, UsingRabbitMq method is used.</p><h3>Docker-Compose</h3><p>The final part is to configure hosting environment. We are going to run our RabbitMQ, producer and consumer apps on docker so that we need to set up docker-compose.yml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb91c1c7f87eca8068246da2217da262/href">https://medium.com/media/fb91c1c7f87eca8068246da2217da262/href</a></iframe><h3>Demo Time</h3><p>After the configurations and implementation, fun side of these came up. It’s time to test our code. Ensuring we have both the Producer and Consumer applications set up run on startup, running docker compose initiates the environment then go to swagger on a browser and trigger the api https://localhost:7047/swagger/index.html</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JdiikXdorRm5D83LhUHh7g.png" /></figure><p>Api publishes the message and returns success. Let’s see what console looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tx0O0qdnqNukeMNhIrXcBw.png" /></figure><p>Our message’s printed in the console.</p><h3>Conclusion</h3><p>In this article, we’ve learned about usage of MassTransit with RabbitMQ. MassTransit is powerful message bus library. If message brokers are needed in a .NET project, MassTransit will be useful solution to work with message brokers in terms of ease of use and managing the problems.</p><p>You can look at the complete example on <a href="https://github.com/alikrc/MasstransitDemo">GitHub</a>.</p><p>Special thanks to <a href="https://medium.com/@alikrc">Ali Karaca</a> and <a href="https://medium.com/@evrenpehlivan">Evren Pehlivan</a> for great contributions on this medium story.</p><p>We also used some references. We are also thanking them :)</p><p><a href="https://code-maze.com/masstransit-rabbitmq-aspnetcore/">Code Maze</a> <a href="https://masstransit-project.com/">MassTransit</a></p><p>Thank you for reading :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6118377bfedb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/multinetinventiv/publish-and-consume-messages-with-masstransit-and-rabbitmq-on-net-6-6118377bfedb">Publish and Consume Messages with MassTransit and RabbitMQ on .Net 6</a> was originally published in <a href="https://medium.com/multinetinventiv">inventiv</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RxSwift and Reactive Programming]]></title>
            <link>https://medium.com/multinetinventiv/rxswift-and-reactive-programming-a0920317deb0?source=rss-4fb2bfef3455------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0920317deb0</guid>
            <category><![CDATA[rxswift]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Ceyhun ÜNLÜ]]></dc:creator>
            <pubDate>Thu, 08 Apr 2021 12:44:57 GMT</pubDate>
            <atom:updated>2021-04-08T12:44:57.380Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CHgFG66Ue0LKHSoJR9Ogcw.jpeg" /></figure><h3>What is RxSwift?</h3><blockquote><strong><em>RxSwift</em></strong> is a library for composing asynchronous and event-based code by using observable sequences and functional style operators, allowing for parameterized execution via schedulers. <em>RxSwift</em> in its essence simplifies developing asynchronous programs by allowing code to react to new data and process it in a sequential and isolated manner.</blockquote><p>It may seem intimidating to understand the concepts behind reactive programming at first but when you get familiar with reactive programming and RxSwift, it will help you to write better apps. Especially when writing asynchronous and event-based code, RxSwift will help you to maintain codebase with minimum effort.</p><h3>Introduction to asynchronous programming</h3><p>Asynchronous programming is a means of parallel programming in which a unit of work runs separately from the main application thread and notifies the calling thread of its completion, failure or progress. You may be wondering when you should use asynchronous programming and what are its benefits and problem points.</p><p>The main benefits one can gain from using asynchronous programming are improved application performance and responsiveness. One particularly well suited application for the asynchronous pattern is providing a responsive UI in a client application while running a computationally or resource expensive operation.</p><p>To explain asynchronous programming in a simple way, let’s give an example from an iOS app. In the iOS app, at any moment, we might be doing any of the following things;</p><ul><li>Reacting to button taps</li><li>Animating the UIView transitions</li><li>Downloading bits of data from remote source</li><li>Playing audio or video</li><li>Saving bits of data to disk</li></ul><p>All things seemingly happen at the same time. Whenever the views are animates, the audio in your app doesn’t pause until animation finished. All different part of your program don’t block each other’s execution. There are various kinds of APIs that allow to perform different pieces of work on different threads, across different execution contexts and perform them across the different cores of the device’s CPU.</p><p>To write code that truly runs in parallel is complex, especially when different bits of code need to work with the same pieces of data. It’s hard to know which piece of code updates the data first or which code read the latest value.</p><h4>Cocoa and UIKit asynchronous APIs</h4><p>Apple has always provided numerous APIs in the iOS SDK that help you write asynchronous code. In fact the best practices on how to write asynchronous code on the platform have evolved many times over the years.</p><p>You’ve probably used many of these in your projects and probably haven’t given them a second thought because they are so fundamental to writing mobile apps.</p><p>To mention few, you have a choice of:</p><ul><li><strong>NotificationCenter</strong>: To execute a piece of code any time an event of interest happens, such as the user changing the orientation of the device or the software keyboard showing or hiding on the screen.</li><li><strong>The delegate pattern</strong>: Lets you define an object that acts on behalf, or in coordination with, another object.</li><li><strong>Grand Central Dispatch</strong>: To help you abstract the execution of pieces of work. You can schedule blocks of code to be executed sequentially, concurrently, or after a given delay.</li><li><strong>Closures</strong>: To create detached pieces of code that you can pass around in your code, and finally</li></ul><h3>Foundation of RxSwift</h3><p>Reactive programming has been around for a fairly long time, but its core concepts have made noticeable over last years. In this years apps became more complex and need to managing complex asynchronous UIs. On the server side, reactive systems have become a necessity.</p><p>Microsoft offered a new client and server side framework called Reactive Extensions for .NET (Rx) to solve the problems of asynchronous, scalable development. Rx for .NET has been open source since 2012 permitting other languages and platforms to reimplement same functionality which turned Rx into a cross-platform standard.</p><p>Today we have RxJs, RxKotlin, Rx.Net, RxScale, RxSwift and more. All try to implement the same behavior and similar APIs, based on the Reactive Extensions specification.</p><p>RxSwift works with all the concepts like the original Rx. It tackles mutable state, allows to compose event sequences and improves on architecturel concepts such as code isolation, reusability and decoupling.</p><blockquote>Note: You can find more info about Rx implementations at <a href="http://reactivex.io/">http://reactivex.io</a></blockquote><h3>Main building blocks of Rx</h3><p>Main building blocks of Rx code are observables, operators and schedulers.</p><p><strong>Observable</strong></p><p>Rx is a generic abstraction of computation expressed through Observable&lt;Element&gt; interface that broadcast and subscribe to values and other events from an Observable stream. The ObservableType protocol (to which Observable conforms) is extremely simple. An Observable can emit (and observers can receive) only three types of events:</p><ul><li><strong>A </strong><strong>next event</strong>: An event that “carries” the latest (or “<strong>next</strong>”) data value. This is the way observers “receive” values. An Observable may emit an indefinite amount of these values, until a terminating event is emitted.</li><li><strong>A </strong><strong>completed event</strong>: This event terminates the event sequence with success. It means the Observable completed its lifecycle successfully and won’t emit additional events.</li><li><strong>An </strong><strong>error event</strong>: The Observable terminates with an error and will not emit additional events.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4EnUDa0Oq9Na1eYtoOM7yg.png" /></figure><p>This workflow accurately describes the lifecycle of a typical observable. Take a look at the related code below:</p><pre>API.download(file: &quot;http://www...&quot;)<br>   .subscribe(<br>     onNext: { data in<br>      // Append data to temporary file<br>     },<br>     onError: { error in<br>       // Display error to user<br>     },<br>     onCompleted: {<br>       // Use downloaded file<br>     }<br>   )</pre><p>API.download(file:) returns an Observable&lt;Data&gt; instance, which emits Datavalues as chunks of data fetched over the network.</p><p>You subscribe for next events by providing the onNext closure. In the downloading example, you append the data to a temporary file stored on disk.</p><p>You subscribe for an error by providing the onError closure. In this closure, you can display the error.localizedDescription in an alert box or otherwise handle your error.</p><p>Finally, to handle a completed event, you provide the onCompleted closure, where you can push a new view controller to display the downloaded file or anything else your app logic dictates.</p><p><strong>Operators</strong></p><p>ObservableType and the implementation of the Observable class include plenty of methods that abstract discrete pieces of asynchronous work and event manipulations, which can be composed together to implement more complex logic. Because they are highly decoupled and composable, these methods are most often referred to as <strong>operators</strong>.</p><p>For example, consider the code you need to react to device orientation changes in your app:</p><ul><li>You add your class as an observer to UIDeviceOrientationDidChangenotifications from NotificationCenter.</li><li>You then need to provide a method callback to handle orientation changes. It needs to grab the current orientation from UIDevice and react accordingly to the latest value.</li></ul><p>This sequence of orientation changes does not have a natural end. As long as there is a device, there is a possible sequence of orientation changes. Further, since the sequence is virtually infinite and stateful, you always have an initial value at the time you start observing it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D5nWwlJxxp4v9svoUpvi7g.png" /></figure><p>It may happen that the user never rotates their device, but that doesn’t mean the sequence of events is terminated. It just means there were no events emitted.</p><p>Here’s the example about observing orientation changes with using some common Rx operators:</p><pre>UIDevice.rx.orientation<br>  .filter { $0 != .landscape }<br>  .map { _ in &quot;Portrait is the best!&quot; }<br>  .subscribe(onNext: { string in<br>    showAlert(text: string)<br>  })</pre><p>Each time UIDevice.rx.orientation produces either a .landscape or .portraitvalue, RxSwift will apply filter and map to that emitted piece of data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*AxaH_wxeSiv4x3DUPH6fdQ.png" /></figure><p>First, filter will only let through values that are not .landscape. If the device is in landscape mode, the subscription code will not get executed because filter will suppress these events.</p><p>In case of .portrait values, the map operator will take the Orientation type input and convert it to a String output — the text &quot;Portrait is the best!&quot;</p><p>Finally, with subscribe, you subscribe for the resulting next event, this time carrying a String value, and you call a method to display an alert with that text onscreen.</p><p><strong>Schedulers</strong></p><p>Schedulers are the Rx equivalent of dispatch queues or operation queues — just on steroids and much easier to use. They let you define the execution context of a specific piece of work.</p><p>RxSwift comes with a number of predefined schedulers, which cover 99% of use cases and hopefully means you will never have to go about creating your own scheduler.</p><p>RxSwift will act as a dispatcher between your subscriptions (on the left-hand side below) and the schedulers (on the right-hand side), sending the pieces of work to the correct context and seamlessly allowing them to work with each other’s output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x3WT-0xIqfPk5-rA32qQ8A.png" /></figure><p>To read this diagram, follow the colored pieces of work in the sequence they were scheduled (1, 2, 3, ...) across the different schedulers. For example:</p><ul><li>The blue network subscription starts with a piece of code (1) that runs on a custom OperationQueue-based scheduler.</li><li>The data output by this block serves as the input of the next block (2), which runs on a different scheduler, which is on a concurrent background GCD queue.</li><li>Finally, the last piece of blue code (3) is scheduled on the Main thread scheduler in order to update the UI with the new data.</li></ul><h3>App architecture</h3><p>It’s worth mentioning that RxSwift doesn’t alter your app’s architecture in any way; it mostly deals with events, asynchronous data sequences and a universal communication contract.</p><p>It’s also important to note that you definitely do not have to start a project from scratch to make it a reactive app; you can iteratively refactor pieces of an exiting project or simply use RxSwift when building new features for your app. You can create apps with Rx by implementing a Model-View-Controller architecture, Model-View-Presenter, or Model-View-ViewModel (MVVM), or any other pattern that makes your life easier.</p><p>We can create apps with Rx by implementing a Model-View-Controller architecture, Model-View-Presenter, or Model-View-ViewModel (MVVM), or any other pattern that makes your life easier. RxSwift and MVVM generally specifically fits each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dYHfoYKZbtrfBqNb.png" /></figure><h3>RxCocoa</h3><p>RxSwift is the implementation of the common, platform-agnostic, Rx specification. It doesnt know anything about any Cocoa or UIKit-specific classes.</p><p>RxCocoa is RxSwift’s companion library holding all classes that specifically aid development for UIKit and Cocoa. It features some advanced classes, RxCocoa adds reactive extensions to many UI components so you can sunbscrive to various UI events out of the box.</p><p>For example it’s very easy to use RxCocoa to subscribe to the state changes of a UISwitch, like this:</p><pre>toggleSwitch.rx.isOn<br>  .subscribe(onNext: { isOn in<br>    print(isOn ? &quot;It&#39;s ON&quot; : &quot;It&#39;s OFF&quot;)<br>  })</pre><p>RxCocoa adds the rx.isOn property to the UISwift class so we can subscribe to useful events as reactive Observable sequences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3H_xnwF8cpXePwfwkWWZvA.png" /></figure><h3>Reactive vs Imperative Programming</h3><h4>Why RxSwift?</h4><p>If your application reacts a lot to user integrations, RxSwift is here to clean up your massive codebase. Let’s take a look at an example of what does it look like with RxSwift.</p><p><em>Example:</em></p><p>Let’s say you have a block of code inside updateUI function. You only want to execute it once the value of isLiked has changed.</p><p><strong>Without RxSwift(</strong>Imperative Programming<strong>):</strong></p><pre><strong>var</strong> isLiked: Bool = <strong>false</strong> {<br>    <strong>didSet</strong> {<br>        <strong>if</strong> isLiked != oldValue {<br>            updateUI()<br>        }<br>    }<br>}</pre><p><strong>With RxSwift:</strong></p><pre><strong>let</strong> isLiked = Variable(<strong>false</strong>)isLiked.asObservable()<br>    .distinctUntilChanged()<br>    .subscribe(onNext: { <br>        updateUI() <br>})</pre><p>Example:</p><p>To prevent the feature’s abuse, you may not want to respond after a certain amount of user integrations. For example, you may only want to respond to the first five changes.</p><p><strong>Without RxSwift:</strong></p><pre><strong>var </strong>likedCount<strong> = 0<br>var</strong> isLiked: Bool = <strong>false</strong> {<br>    <strong>didSet</strong> {<br>        <strong>if</strong> isLiked != oldValue &amp;&amp; likedCount &lt; 5 {<br>            updateUI() <br>            likedCount += 1<br>        }<br>    }<br>}</pre><p><strong>With RxSwift:</strong></p><pre><strong>let</strong> isLiked = Variable(<strong>false</strong>)isLiked.asObservable()<br>    .distinctUntilChanged()<br>    .take(5)<br>    .subscribe(onNext: { <br>        updateUI() <br>})</pre><p>Example:</p><p>Let’s say you don’t want to respond if the value is updating too fast. For example, you don’t want to take action if the value of <strong><em>isLiked </em></strong>has been updated more than once within one second.</p><p><strong>Without RxSwift:</strong></p><pre><strong>var </strong>likedCount<strong> = 0<br>var </strong>isLikedEnabled<strong> = true<br>var</strong> isLiked: Bool = <strong>false</strong> {<br>    <strong>didSet</strong> {<br>        <strong>if</strong> isLiked != oldValue &amp;&amp; likedCount &lt; 5 &amp;&amp; isLikedEnabled {<br>            updateUI() <br>            likedCount += 1<br>            isLikedEnabled = false                                     Timer.scheduledTimer(withTimeInterval: 1000, repeats: <strong>false</strong>) { _ <strong>in</strong>                isLikedEnabled = <strong>true<br>            </strong>}<br>        }<br>    }<br>}</pre><p><strong>With RxSwift:</strong></p><pre><strong>let</strong> isLiked = Variable(<strong>false</strong>)isLiked.asObservable()<br>    .debounce(1)   <br>    .distinctUntilChanged()<br>    .take(5)<br>    .subscribe(onNext: { <br>        updateUI() <br>})</pre><p><strong>Conclusion</strong></p><p>Reactive Programming is actually way more powerful than what you’ve seen. Even though I did not showcase everything Rx can do, but I think the outcome is very obvious. As you can see from the above examples, as the app becomes more complex, the benefits of using RxSwift will become more outstanding.</p><p>Reactive applications are solid, easier to test and more agile about their user experience. With data bindings, your apps UI is always up to date and allow you to craft complex app logic with minimum effort.</p><p>References:</p><p><a href="https://www.raywenderlich.com/books/rxswift-reactive-programming-with-swift/v4.0/chapters/1-hello-rxswift">https://www.raywenderlich.com/books/rxswift-reactive-programming-with-swift/v4.0/chapters/1-hello-rxswift</a></p><p><a href="https://medium.com/ios-os-x-development/learn-and-master-%EF%B8%8F-the-basics-of-rxswift-in-10-minutes-818ea6e0a05b">https://medium.com/ios-os-x-development/learn-and-master-%EF%B8%8F-the-basics-of-rxswift-in-10-minutes-818ea6e0a05b</a></p><p><a href="https://medium.com/@mapleong/implementing-rxswift-vs-swift-delegate-9de3ba59a87">Implementing RxSwift vs. Swift Delegate</a></p><p>Thanks to <a href="https://medium.com/u/104b6dd1bc69">Ilkersevim</a>, <a href="https://medium.com/u/e55e57473c5f">Ramazan Oz</a> and <a href="https://medium.com/u/a834c46aa750">Mert Ejder</a> for preparing this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0920317deb0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/multinetinventiv/rxswift-and-reactive-programming-a0920317deb0">RxSwift and Reactive Programming</a> was originally published in <a href="https://medium.com/multinetinventiv">inventiv</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automate Build and Deployment of Azure SQL Database using Azure DevOps with Azure Pipelines]]></title>
            <link>https://medium.com/multinetinventiv/automate-build-and-deployment-of-azure-sql-database-using-azure-devops-with-azure-pipelines-9cf9b576b5c1?source=rss-4fb2bfef3455------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cf9b576b5c1</guid>
            <category><![CDATA[english]]></category>
            <category><![CDATA[automate]]></category>
            <category><![CDATA[azure-sql-database]]></category>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[azure-pipelines]]></category>
            <dc:creator><![CDATA[Ceyhun ÜNLÜ]]></dc:creator>
            <pubDate>Thu, 09 Jul 2020 05:27:01 GMT</pubDate>
            <atom:updated>2020-07-09T05:27:01.111Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*jvPNwoicXE5BdLPxnsv95Q.png" /></figure><p>Continuous integration and continuous deployment make efficiency, standardization and repeatability to development and production processes of a product. Databases are part of the product so we cannot imagine application delivery process without database.</p><p>There are a lot of CI/CD tools available, and Azure DevOps with Azure Pipelines is a very powerful and popular CI/CD tool for automation.. In this article, I am going to demonstrate how to add database to CI/CD using Azure DevOps with Azure Pipelines.</p><p>Please note that this article assumes the following pre-conditions:</p><ol><li>You are using Visual Studio.</li><li>You are using a repository supported by Azure DevOps.</li><li>You have a subscription to be able to use Azure Pipelines.</li><li>You are using Azure SQL and it has a user with <em>dbowner</em> role for the pipelines.</li><li>You have a database project created by using Visual Studio Template.</li></ol><h3>Create Schema</h3><p>Once you have Azure SQL, your database is already initialized in the server. Database schema needs to be created in the project. Instead of defining schema manually, you can import an existing database by using <em>Import &gt; Database.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wgvMManHBAdzXknqcT3GQg.png" /></figure><p>Schema changes, adding procedures and implementing post &amp; predeployment scripts can be done from the project. Since this is a simple CI/CD flow, I am not going to explain details of managing project usage. Depending on your flow, usage of the project can be changed to provide needs of development team, rollback and versioning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LHdmVdvrQyoDSOOkUlB_BA.png" /></figure><h3>Creating Database Publish Profile</h3><p>Publish profile is used to decide what to continuously deploy. From the solution explorer, right click on database project and choose Publish. Following dialog will appear. Configure the publish settings then click on Create Profile button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GRaRReGHVkoBzfGOuRdHJw.png" /><figcaption>Since there are a lot of options, you may want to consult to a DBA for appropriate settings for your environment. If you are in doubt, it is better to leave settings as they are to avoid potential errors on deployment.</figcaption></figure><p>If you have completed the project settings, push the changes to the repository and move on to setting up the build pipeline.</p><h3>Setup Build Pipeline</h3><p>When a change is pushed repository, a build pipeline is required to build the project and generate dacpac. To create the build pipeline, go to <strong><em>Pipelines</em></strong> page from the left menu of Azure DevOps then click on <strong><em>Create pipeline</em></strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dw-4v58vERubNQd4VBwm-Q.png" /></figure><p>There are two configuration options for pipeline. You can create pipeline by using YAML or classic Editor. I am going to use classic Editor in this example. Click on <strong><em>Use the classic editor</em></strong> link after the page loads. Now choose your repository and click on <strong><em>Continue</em></strong>. I am using <a href="https://azure.microsoft.com/en-us/services/devops/repos/">Azure Repos Git</a> as source in this example. We don’t need the template so just choose <strong><em>Empty</em></strong> <strong><em>job </em></strong>on the next page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*XtOgmYQD8hh8MGrMg5dsKA.png" /></figure><p>After you create an empty job, you will see the page in the following image. You can rename pipeline name as you wish. I preferred MyDatabase as name. Choose an agent for the pipeline. We have only one environment in this project so you can inherit them in agent menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F8Xm5QoFGzXIbCPZo8HEbw.png" /></figure><p>It is better to clean everything when job gets started. Cleaning should be set from <strong><em>Get sources</em></strong> menu in order to make clean build. Click on it then choose <strong><em>true</em></strong> as <strong><em>Clean</em></strong> then choose <strong><em>Source and output directory </em></strong>as<strong><em> Clean options</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3NnCJ60bFv0rZQjmef1VJg.png" /></figure><p>We need to configure the agent before configuring the tasks. The agent chosen from the pipeline needs to be imported so pipeline agent will be used for the pipeline. Next step is to add tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l1XwsJ-9H6sFBTUqM75_4A.png" /></figure><p><strong>1- Build Task</strong></p><p>We need to generate the dacpac file for deployment. If you are unfamiliar with dacpac, you can find the detail information from this <a href="https://docs.microsoft.com/en-us/sql/relational-databases/data-tier-applications/data-tier-applications?view=sql-server-ver15"><em>link</em></a>. In order to generate the dacpac file, we need to build our database project. For that, we will add<em> </em><strong><em>Visual Studio build</em></strong> task. Some required fields are needed to be filled. Pick <strong><em>Visual Studio 2017</em></strong> or higher as <strong><em>Visual Studio Version</em></strong>. Add given text under following image as <strong><em>MSBuild Arguments</em></strong>. Considering that solution supports any platform and has only release configuration, enter <strong><em>any cpu</em></strong> as <strong><em>platform</em></strong>. Choose <strong><em>release</em></strong> as <strong><em>configuration</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q6wDqdN1YCfWb8vXC0M91g.png" /><figcaption><strong>MSBuild Arguments:</strong> /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=”$(build.artifactstagingdirectory)\\”</figcaption></figure><p><strong>2- Copy DacPac</strong></p><p>In order to publish dacpac file, it needs to be copied to artifact staging directory. To do that add <strong><em>Copy files</em></strong> task. Choose folder where dacpac file gets generated after build for <strong><em>Source Folder</em></strong> field. Enter your dacpac file name with file extension in <strong><em>Content</em></strong> field. Enter <strong><em>$(Build.ArtifactStagingDirectory)</em></strong> in <strong><em>Target Folder</em></strong> field. The value used for the last field is <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&amp;tabs=classic">predefined variable</a> for Azure Pipelines and it gives artifact location where <strong><em>Publish Artifact</em></strong> task is going to be used later on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M5rYriOechAdiYZucCFrnA.png" /></figure><p><strong>3- Copy Publish Profile</strong></p><p>Publish profile is required for release pipeline. In order to publish “Publish Profile” file, it needs to be copied to artifact staging directory. To do that add <strong><em>Copy files</em></strong> task. Choose folder where the file is stored in the solution for <strong><em>Source Folder</em></strong> field. Enter your publish profile file name with file extension in <strong><em>Content</em></strong> field. Enter <strong><em>$(Build.ArtifactStagingDirectory)</em></strong> in <strong><em>Target Folder</em></strong> field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*srHQW5G8MUHfdpP2jWCdqA.png" /></figure><p><strong>4- Publish artifact</strong></p><p>Final task to complete task configuration is publish artifact task. This task publishes dacpac file and publish profile as build artifact. This will be used for release pipeline. To make that, add <strong><em>Publish build artifacts</em></strong> task. Enter <strong><em>$(Build.ArtifactStagingDirectory)</em></strong> in <strong><em>Path to publish </em></strong>field</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dPMnRg8jyJ-soOcyBc5OEQ.png" /></figure><p>In order to provide continuous integration, it needs to be activated from trigger tab. Open its page from the tab, check <strong><em>Enable continuous integration </em></strong>then branch filter is required to be added. Choose the appropriate branch for your release flow. Now, build configuration is completed. Save &amp; queue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dwHax5QdOhYhlHuJz3NzkA.png" /></figure><p>When a change is pushed to the branch, build pipeline will be executed. Each build can be seen on the pipeline page. In addition to this, you can also trigger a build manually from its page.</p><h3>Setup Release Pipeline</h3><p>In order to provide continuous deployment with Azure Pipelines, release pipeline needs to be configured. To create the release pipeline, go to <strong><em>Releases</em></strong> page from the left menu of Azure DevOps then click on <strong><em>New pipeline</em></strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vrjTBafP8i-mrv4b7q_SKA.png" /></figure><p>When release creation is opened, Azure automatically adds a stage and prompts user to pick a template that is going to be used in the pipeline. No template is needed for our case. We are going to create our stage as empty so so choose <strong><em>Empty</em></strong> <strong><em>job</em></strong> then rename the stage name and pipeline name as you wish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tDM19dML4QHCaKqgYoP84g.png" /></figure><p>In previous steps, we created the build pipeline and now we will integrate it with the release pipeline. First, we need to set the artifact. Click on <strong><em>Add</em></strong> button in the artifacts box, choose <strong><em>Build</em></strong> as the source type, fill the required fields then click <strong><em>Add</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*ndcv8q_KECnRgcDkcvBuJA.png" /></figure><p>We now configured the database artifact. In order to provide continuous deployment, we need to set the trigger for the artifact. Once we activate the trigger, when the build pipeline generates a new artifact the release pipeline will be executed. You can see how to activate trigger from the following picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KjCIwzx49PkvfMVOBYKJXA.png" /><figcaption><strong>Note: </strong>Depending on the build branch repository, build branch filters can be applied. In this example, we have only one branch which is master so there is no need for branch filters.</figcaption></figure><p>Now, we can move to the next part which is configuring stage part to complete the configuration. Stages and jobs inside of each stages depends on your release flow. Especially for the production environment, there are many parameters (versioning, backup, etc.) that needs to be considered for the flow. In this context, we are going to create a simple release flow that handles only deployment. Click on the link inside of <strong><em>Stage 1</em></strong>. Pick up an agent that has sql package installed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7V6XJyfnhetpZKg1DIv6Bw.png" /><figcaption><strong>Note:</strong> Current DevOps subscription includes user-hosted-agent. Network and privacy settings needed to be configured before creating the pipeline so that this agent can make deployment to Azure SQL.</figcaption></figure><p>In this stage, we will run the scripts on Azure SQL using the dacpac file we created with the build pipeline. A related task needs to be added into the stage. Follow below picture to find the <strong><em>Azure Sql Database deployment</em></strong> task and add it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S1u_Ojzfirr7frgbeyi1Cw.png" /></figure><p>After adding the task, there are some required fields to be set. First of all, a subscription needs to be chosen. This subscription must have related permissions to maintain the Azure Sql. Subscription can be chosen in dropdown menu which is shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FNiQY4TMuFmY6EkIkRfYMQ.png" /></figure><p>Now we need to set SQL Database fields in order to execute deployment scripts. In this case, we are going to use SQL Server Authentication as Authentication Type. A user must be defined in master database on the Azure SQL server. Enter database name and login credentials for the next fields. Anything wrapped in $() means it is a variable. You can read more about them <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&amp;tabs=yaml">here</a>. In this example, database name, login and password values are set from the variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bpxwYlwIfBUOwlm6JEmvVg.png" /></figure><p>We keep everything in the database project and everything including predeploy and post deploy scripts are generated when the project gets built so that <strong><em>SQL DACPAC File</em></strong> as deploy type must be chosen. Enter path of dacpac file and publish profile. The buttons which are near each path fields can be used to find the file.</p><p>Final step before saving the pipeline is to set variables. In this example, we used pipeline variables. They can be set under variables tab which is shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IYS8rE6L9yihGU31KC73mg.png" /></figure><p>Now everything that are required to be filled are set. It is time to save the pipeline and test. Once it is saved, release pipeline is ready to use. Now, make some changes in the project and push the changes. When the changes gets pushed, build pipeline will be triggered, and after a successful build the release pipeline will be triggered.</p><p>There are many tools for integrating databases into CI/CD processes. In this article, I tried to show how to integrate a database project using Azure Pipelines. Using automation tools reduces human error margin and leads to a more maintainable project so we need to automate our processes as much as we can.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cf9b576b5c1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/multinetinventiv/automate-build-and-deployment-of-azure-sql-database-using-azure-devops-with-azure-pipelines-9cf9b576b5c1">Automate Build and Deployment of Azure SQL Database using Azure DevOps with Azure Pipelines</a> was originally published in <a href="https://medium.com/multinetinventiv">inventiv</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>