<?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: Decebal Dobrica</title>
    <description>The latest articles on DEV Community by Decebal Dobrica (@ddonprogramming).</description>
    <link>https://dev.to/ddonprogramming</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%2F30234%2F00a36c85-5f5b-46aa-92b4-5b065f2305de.jpg</url>
      <title>DEV Community: Decebal Dobrica</title>
      <link>https://dev.to/ddonprogramming</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ddonprogramming"/>
    <language>en</language>
    <item>
      <title>Message Pack for PHP 7.2 - Server &amp; Client implementations</title>
      <dc:creator>Decebal Dobrica</dc:creator>
      <pubDate>Thu, 15 Mar 2018 09:54:11 +0000</pubDate>
      <link>https://dev.to/ddonprogramming/message-pack-for-php-72---server--client-implementations--39kb</link>
      <guid>https://dev.to/ddonprogramming/message-pack-for-php-72---server--client-implementations--39kb</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fhpiynhbhq%2Fimage%2Fupload%2Fv1520644966%2Fip3wvid0edmroovpe5yt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fhpiynhbhq%2Fimage%2Fupload%2Fv1520644966%2Fip3wvid0edmroovpe5yt.png" alt="messagepack.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This package tries to leverage the power of &lt;a href="https://msgpack.org/index.html" rel="noopener noreferrer"&gt;Message Pack&lt;/a&gt; and &lt;a href="https://github.com/rybakit/msgpack.php" rel="noopener noreferrer"&gt;msgpack.php&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mainly this uses &lt;a href="https://github.com/msgpack-rpc/msgpack-rpc-php" rel="noopener noreferrer"&gt;https://github.com/msgpack-rpc/msgpack-rpc-php&lt;/a&gt; while updating the underlying code &amp;amp; upgrading to the above mentioned msgpack.php package.&lt;/p&gt;

&lt;h3&gt;
  
  
  There are 3 possible use cases for this repository due to it's server &amp;amp; client perspectives
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Client (my main use case)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt; &lt;span class="nv"&gt;$client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'localhost'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'1985'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

 &lt;span class="nv"&gt;$messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"SyncJob"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$job&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$payload&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

 &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;array_pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$messages&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;aside from the obvious &lt;code&gt;host&lt;/code&gt; and &lt;code&gt;port&lt;/code&gt; arguments for the &lt;code&gt;Client&lt;/code&gt; class, let's see the arguments for the call function:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;first argument is a string naming the function to be called on the server side (see &lt;code&gt;tests/server.php&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;the &lt;code&gt;call&lt;/code&gt; method is a variadic function, hence the following arguments are concatenated to an array on the server &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Server (not thoroughly tested)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nv"&gt;$server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'1985'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
      &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Server is listening on port 1985...'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;recv&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;see &lt;code&gt;tests/server.php&lt;/code&gt; for full example&lt;/p&gt;

&lt;h4&gt;
  
  
  Client and Server
&lt;/h4&gt;

&lt;p&gt;this would be a good use case if you use multiple services or you need back and forth communication&lt;/p&gt;

&lt;p&gt;*if you need this between the same 2 services maybe best to take into account switching to http/2 where&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;     &lt;span class="nv"&gt;$backChannel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BackChannel&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

     &lt;span class="nv"&gt;$client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'localhost'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'1986'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$backChannel&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    
     &lt;span class="nv"&gt;$messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"SyncJob"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$job&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$payload&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    
     &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;array_pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$messages&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

     &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nv"&gt;$server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Server&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'1985'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nv"&gt;$backChannel&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
         &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Server is listening on port 1985...'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
         &lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;recv&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in this case, as it was the case for the original package, it makes sense to use the BackChannel’s combined server and client methods.&lt;/p&gt;

&lt;h3&gt;
  
  
  Other options
&lt;/h3&gt;

&lt;p&gt;The package provides necessary interfaces &amp;amp; Traits in order to have your own Server or Client enhancements without the need to modify the base classes whom one can mainly use as references rather than implementations as it makes only for the most basic use case. &lt;/p&gt;

&lt;h3&gt;
  
  
  a few words on the impact of switching to MessagePack from Gearman
&lt;/h3&gt;

&lt;p&gt;I expected the time to first byte to be affected, but given that they both communicate at a low level the benchmarks were almost the same to the byte.&lt;/p&gt;

&lt;p&gt;There is a huge change in availability as I expected however, which is solving one big problem for my system.&lt;/p&gt;

&lt;p&gt;I am curious to hear what was your experience and how you used it or looking to use it for, please comment below.&lt;/p&gt;




&lt;p&gt;Originally published at &lt;a href="https://utopian.io/utopian-io/@decebal2dac/message-pack-for-php-server-and-client-libraries" rel="noopener noreferrer"&gt;Utopian.io -  Rewarding Open Source Contributors&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Domain Driven Design with React Native</title>
      <dc:creator>Decebal Dobrica</dc:creator>
      <pubDate>Tue, 21 Nov 2017 10:04:05 +0000</pubDate>
      <link>https://dev.to/ddonprogramming/domain-driven-design-with-react-native-1k0</link>
      <guid>https://dev.to/ddonprogramming/domain-driven-design-with-react-native-1k0</guid>
      <description>&lt;p&gt;Problem: &lt;/p&gt;

&lt;p&gt;how to guide programmers to implement domain driven design and &lt;a href="https://dzone.com/refcardz/patterns-modular-architecture"&gt;modular architectecture&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Relevant technologies used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;apollo client&lt;/li&gt;
&lt;li&gt;graphql&lt;/li&gt;
&lt;li&gt;react native&lt;/li&gt;
&lt;li&gt;nodejs&lt;/li&gt;
&lt;li&gt;redux&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a programmer I am always inclined to prioritise technical detail and &lt;code&gt;just making things work&lt;/code&gt;.&lt;br&gt;
One of the techniques to prevent building monolithic code bases closed to expansion is constant refactoring.&lt;/p&gt;

&lt;p&gt;An architecture trick I picked up from developing Domain Driven Design is to twick the questions. When refactoring, I would usually ask myself "what does this object do ?", which is a question about the domain, instead of "how do I make all these pieces work together", a question about the underlying technologies or infrastructure.&lt;/p&gt;

&lt;p&gt;In order to allow for paced development I learned that designing the Domain can be a longer process, as long as everyone agrees with the bigger picture and they work towards that goal.&lt;/p&gt;

&lt;p&gt;Given that I decided to work on a goal using the techniques available with the technologies at hand. The architecture I used with PHP for refactoring a monolith looks something within these lines:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight mosel"&gt;&lt;code&gt;&lt;span class="n"&gt;application&lt;/span&gt;
     &lt;span class="n"&gt;controllers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;web&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;specific&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
     &lt;span class="n"&gt;services&lt;/span&gt;
&lt;span class="k"&gt;model&lt;/span&gt;
     &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;bounded&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;contexts&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
              &lt;span class="n"&gt;entities&lt;/span&gt;
              &lt;span class="n"&gt;interfaces&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;contracts&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;domain&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;infrastructure&lt;/span&gt;
     &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;bounded&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="n"&gt;contexts&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
          &lt;span class="n"&gt;services&lt;/span&gt;
&lt;span class="n"&gt;persistence&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;These generic lines can be followed in most languages, implementation and need for some of these parts however can be missed, in particular a react-native app could have little to no persistence needs to start with, but I would expect that to grow more important and ingrained in the domain model if fragments are used with the domain in mind.&lt;/p&gt;

&lt;p&gt;As an extra when developing a react-native first code-base my lead question I like to ask when thinking about architecture is: &lt;code&gt;how would a web app use this module ?&lt;/code&gt; . That is mainly due to the ability to swap presentation components from react native to react and get a web experience out of the same underlying logic.&lt;/p&gt;

&lt;p&gt;While doing some research on the subject &lt;a href="http://code.viget.com/microcosm/guides/quickstart.html"&gt;Microcosm&lt;/a&gt; came the closest in terms of best help in modeling the domain I could find.&lt;br&gt;
Microcosm can come out as a candidate for replacing redux in an application, however microcosm has rules of Domain Driven Design ingrained and can be used just as an architecture example at times.&lt;br&gt;
Their recommendation &lt;a href="https://www.viget.com/articles/microcosm-our-data-layer-for-react"&gt;here&lt;/a&gt; might look like replacing redux, when building a relatively small app or just when starting that might be quite a fair assessment, I can see them work together, although redux might influence the architecture slightly as well.&lt;/p&gt;

&lt;p&gt;One other big influence over your infrastructure will be &lt;a href="https://reactarmory.com/answers/how-should-i-separate-components"&gt;How you separate your components&lt;/a&gt; , the guys at armory talk about 4 component types, some might discard some a couple types when in a domain that has different boundaries defined, I can see these services (I would still use service components or functions) growing big as well, so at times these 4 categories will make sense.&lt;/p&gt;

&lt;p&gt;These &lt;a href="https://techblog.appnexus.com/five-tips-for-working-with-redux-in-large-applications-89452af4fdcb"&gt;tips on working with redux in Large Applications&lt;/a&gt; are still relevant. A correct use of the domain tools would keep separation between data objects, but the other tips are brilliant, at least to be aware of.&lt;/p&gt;

&lt;p&gt;Given that, I hope I gave you something to think of, chew while developing or refactoring your next react native app.&lt;br&gt;
Don't be shy to comment if you disagree or if you feel some of these views are completely out of wack.&lt;/p&gt;

&lt;p&gt;Would appreciate any kind of feedback as this is an ongoing development.&lt;/p&gt;

&lt;p&gt;Also published on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://decebalonprogramming.net/post/domain-driven-design-with-react-native/"&gt;https://decebalonprogramming.net/post/domain-driven-design-with-react-native/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@decebaldobrica/domain-driven-design-with-react-native-fe7530b8696e"&gt;https://medium.com/@decebaldobrica/domain-driven-design-with-react-native-fe7530b8696e&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://steemit.com/software-architecture/@decebal2dac/domain-driven-design-with-react-native"&gt;https://steemit.com/software-architecture/@decebal2dac/domain-driven-design-with-react-native&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>architecture</category>
      <category>ddd</category>
      <category>reactnative</category>
      <category>node</category>
    </item>
  </channel>
</rss>
