<?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: Hamida</title>
    <description>The latest articles on DEV Community by Hamida (@haamida).</description>
    <link>https://dev.to/haamida</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%2F158910%2Fc9181c25-25c5-4dff-9ae8-41828a436e09.jpg</url>
      <title>DEV Community: Hamida</title>
      <link>https://dev.to/haamida</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/haamida"/>
    <language>en</language>
    <item>
      <title>Docker Part 1 : A brief theoretical overview</title>
      <dc:creator>Hamida</dc:creator>
      <pubDate>Sun, 16 Feb 2020 09:16:55 +0000</pubDate>
      <link>https://dev.to/haamida/docker-part-1-a-brief-theoretical-overview-50ec</link>
      <guid>https://dev.to/haamida/docker-part-1-a-brief-theoretical-overview-50ec</guid>
      <description>&lt;p&gt;Although I am using Docker for a while now, the theory always seemed a bit complex to me, so I decided to do the in depth search to understand the theory and put it for me and others in simpler words. Although it wouldn't be as simple as this one line from the Stack Overflow user 'L0j1k' that kinda sums it all up :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Docker is just a fancy way to run a process.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  But first Virtualisation
&lt;/h1&gt;

&lt;p&gt;Virtualisation in a broad sense means creating a simulated, virtual computing environment. &lt;br&gt;
There are four virtualisation categories: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Desktop virtualisation&lt;/em&gt;: where a centralised machine manage individualized desktops,&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Network virtualisation&lt;/em&gt;: where a network bandwidth is split into independent channels to be assigned to different device, &lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Storage virtualisation&lt;/em&gt;: where a hardware storage information is abstracted to create a logical view of storage to be consumed by devices,&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Software virtualisation&lt;/em&gt;: where in a hosting physical environment, we get to create several isolated virtual environments.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  What about Docker ?
&lt;/h1&gt;

&lt;p&gt;Docker is not under any of the above categories. It's a container-based virtualisation (OS-level one ). &lt;br&gt;
All the containers on the host machine share the same kernel and run on the same OS as the host. Each container is identified by a namespace so the kernel can insure the execution isolation.&lt;/p&gt;

&lt;h1&gt;
  
  
  So containers ?
&lt;/h1&gt;

&lt;p&gt;A container ideally runs a single process, it's stateless also so it can be created and destroyed without affecting the application behavior.&lt;br&gt;
Since an application usually use multiple containers, Docker offers a YAML  configuration file, that allow us to build the different containers and put them on the same virtual network. &lt;/p&gt;

&lt;h1&gt;
  
  
  What's an Image then ?
&lt;/h1&gt;

&lt;p&gt;Easily put, a Docker Image is a &lt;em&gt;read-only&lt;/em&gt; template of instructions to create a docker container. &lt;br&gt;
It's the equivalent of an &lt;em&gt;Immutable&lt;/em&gt; VM snapshot.&lt;br&gt;
It's the snapshot of the docker container at a specific point of time that contains all the elements needed to run an application (code, configuration files, librairies,etc.)&lt;/p&gt;

&lt;p&gt;See you soon in the practical part about Docker (a link would be added later when the other part is up).&lt;/p&gt;

</description>
      <category>docker</category>
    </item>
    <item>
      <title>Using RabbitMQ in a Symfony 3.4 project -- Part1: Producer --</title>
      <dc:creator>Hamida</dc:creator>
      <pubDate>Sun, 25 Aug 2019 19:26:21 +0000</pubDate>
      <link>https://dev.to/haamida/using-rabbitmq-in-a-symfony-3-4-project-part1-2m4p</link>
      <guid>https://dev.to/haamida/using-rabbitmq-in-a-symfony-3-4-project-part1-2m4p</guid>
      <description>&lt;p&gt;When I had to use RabbitMQ in a symfony project, I had a hard time with the choice of bundle or Component to use, so in this example I am creating a fully fonctionnal example using Enqueue and symfony 3.4.&lt;br&gt;
As per the Enqueue choice, I find it (&lt;a href="https://enqueue.forma-pro.com/"&gt;enqueue.forma-pro.com&lt;/a&gt;) the best documented solution for php projects coupled with a wide range of transports to message brokers (amqp, redis, kafka,...).&lt;/p&gt;

&lt;p&gt;This example will allow us to make connect to different endpoints available for &lt;strong&gt;r/SpaceX API&lt;/strong&gt; on a random way. All the code examples and configurations are strictly usefull with the &lt;strong&gt;0.9.12&lt;/strong&gt; version of the &lt;strong&gt;enqueue-bundle&lt;/strong&gt;.&lt;br&gt;
The full code can be found on &lt;a href="https://github.com/Haamida/RestRabbit"&gt;https://github.com/Haamida/RestRabbit&lt;/a&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Configuration
&lt;/h4&gt;

&lt;p&gt;The first setp would be to run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer require enqueue/enqueue-bundle enqueue/amqp-lib
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;enqueue/amqp-lib&lt;/em&gt; here is my library of choice to connect to RabbitMQ. I should mention here that amqp-lib depends on the bcmath extension so you have to make sure that its installed or enbaled.&lt;/p&gt;

&lt;p&gt;Now that the bundle is added to the project (composer.json and AppKernel.php), let's procede with a minimalistic config in enqueue.yml :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enqueue:
  default:
    transport: 'amqp+lib:'
    client: ~
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now the connection parameters in parameters.yml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    queue_rb: spacex_q
    topic_rb: spacex_t
    host_rb: 127.0.0.1
    port_rb: 5672
    user_rb: guest
    pass_rb: guest
    vhost_rb: /
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here for simplicity,I kept the default port, user,vhost,...( Sure that should be changed for production).&lt;br&gt;
It would be usefull to have the Rabbit Management plugin enbaled to monitor the interactions with the queue :&lt;br&gt;
&lt;code&gt;rabbitmq-plugins enable rabbitmq_management&lt;/code&gt; &lt;br&gt;
Now head for &lt;code&gt;http://localhost:15672/&lt;/code&gt; to get an overview of the queues and messages.&lt;/p&gt;
&lt;h4&gt;
  
  
  2. Connection, Topic and Queue
&lt;/h4&gt;

&lt;p&gt;To send our produced messages to the queue, we need to set up our connection.&lt;br&gt;
First step would be to get an instance of the connection Factory :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$factory = new AmqpConnectionFactory([
            'host' =&amp;gt; $this-&amp;gt;getParameter('host_rb'),
            'port' =&amp;gt; $this-&amp;gt;getParameter('port_rb'),
            'vhost' =&amp;gt; $this-&amp;gt;getParameter('vhost_rb'),
            'user' =&amp;gt; $this-&amp;gt;getParameter('user_rb'),
            'pass' =&amp;gt; $this-&amp;gt;getParameter('pass_rb'),
            'persisted' =&amp;gt; true,
        ]);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That would allow us now to create a &lt;strong&gt;connection context&lt;/strong&gt; a topic and a queue (if they are not already created)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $context = $factory-&amp;gt;createContext();
 $topic = $context-&amp;gt;createTopic($topicName);
 $topic-&amp;gt;setType(AmqpTopic::TYPE_DIRECT);
 $context-&amp;gt;declareTopic($topic);
 $queue=$this-&amp;gt;createOrUseQueue($context,$queueName);
 $context-&amp;gt;bind(new AmqpBind($topic, $queue));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the above code, I created direct exchange type of topic so that the message will be routed directly to the queue with the matching routing key. That's because per rabbitmq message flow, a message is delivered first to an exchange than depending on the exchange type:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Direct&lt;/strong&gt;: sent directly to the corresponding (by routing key)queue &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fanout&lt;/strong&gt;: sent to all the queues bound to the exchange&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Headers&lt;/strong&gt;: sent based on the message headers &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Topic&lt;/strong&gt;: sent to one or more queues based on a correspondance between the routing key and the routing pattern
These are the principle Exchange types, a more in depth explanation can be found here &lt;a href="https://www.cloudamqp.com/blog/2015-09-03-part4-rabbitmq-for-beginners-exchanges-routing-keys-bindings.html"&gt;Exchanges-routing-keys-bindings&lt;/a&gt;.
After configuring the topic, we proceed to create the queue that we later would bind to it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; public function createOrUseQueue($context,$queueName){
        $queue = $context-&amp;gt;createQueue($queueName);
        $queue-&amp;gt;addFlag(AmqpQueue::FLAG_DURABLE);
        $context-&amp;gt;declareQueue($queue);
        return $queue;
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Practically, it's the same logic for creating a topic. I added the flag &lt;code&gt;FLAG_DURABLE&lt;/code&gt; so the queue could survive the broker restart/technical problems. That being said, a durable queue doesn't guarantee that the messages would survive too, they should be labeled persistant to have that effect. &lt;/p&gt;

&lt;h4&gt;
  
  
  Send Message to queue
&lt;/h4&gt;

&lt;p&gt;Now that everything is set, we can produce and send messages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; switch (rand(1, 3)) {
                case 1:
                    $message = $context-&amp;gt;createMessage('roadster');
                    break;
                case 2:
                    $message = $context-&amp;gt;createMessage('rockets');
                    break;
                case 3:
                    $message = $context-&amp;gt;createMessage('missions');
                    break;
                default:
                    $message = $context-&amp;gt;createMessage('info');
            }
$context-&amp;gt;createProducer()-&amp;gt;send($this-&amp;gt;createOrUseQueue($context, $this-&amp;gt;getParameter('queue_rb')), $message);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is all for the producing part, in the next part we will configure our messages to be persistent and create our Consumer that will allow us to get information from the SpaceX API.&lt;/p&gt;

</description>
      <category>rabbitmq</category>
      <category>php</category>
      <category>enqueue</category>
      <category>symfony</category>
    </item>
    <item>
      <title>Fixing React build failure</title>
      <dc:creator>Hamida</dc:creator>
      <pubDate>Sun, 05 May 2019 15:33:02 +0000</pubDate>
      <link>https://dev.to/haamida/fixing-react-build-failure-24o1</link>
      <guid>https://dev.to/haamida/fixing-react-build-failure-24o1</guid>
      <description>&lt;p&gt;I was so enthusiastic about deplying my first react project, a very beginner version.&lt;br&gt;
All that faded away after having to go over and over on 'npm install' and 'npm build' and failing miserably to build my simple one page project.&lt;br&gt;
Hours of search and nothing useful or helpful.&lt;/p&gt;

&lt;p&gt;Turns out, the extra Babel dependencies I added to the project following some tutorials created some sort of a confilct that caused the react-scripts to fail everytime I attempted the build command.&lt;br&gt;
This can be traced in this &lt;a href="https://github.com/facebook/create-react-app/issues/5135"&gt;https://github.com/facebook/create-react-app/issues/5135&lt;/a&gt; issue report.&lt;br&gt;
Now finally, I got to deploy my too naive try after changing the whole app idea and keeping the same weird name (Sneaky-React). (&lt;a href="https://nifty-hypatia-73966f.netlify.com/"&gt;https://nifty-hypatia-73966f.netlify.com/&lt;/a&gt;)&lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
      <category>build</category>
    </item>
    <item>
      <title>Is RabbitMQ a fit solution for request timeout problem ?</title>
      <dc:creator>Hamida</dc:creator>
      <pubDate>Wed, 01 May 2019 16:00:02 +0000</pubDate>
      <link>https://dev.to/haamida/how-can-i-use-rabbitmq-to-connect-to-another-system-40fo</link>
      <guid>https://dev.to/haamida/how-can-i-use-rabbitmq-to-connect-to-another-system-40fo</guid>
      <description>&lt;p&gt;The system am working on relies on the response received from an external API, frequently now, the requests we are sending finish with a timeout and we end up losing the transaction in progress.&lt;/p&gt;

&lt;p&gt;We need our requests to be resent over and over until the API responds so we could continue the transaction.&lt;/p&gt;

&lt;p&gt;I got advised to use RabbitMQ so that it queues the requests until the API responds, so this way my application should be a producer that pushes to the queue, what I still can't undrestand is how I am going to receive a callback from the queue once my message (request is excuted sucessfully) ?&lt;br&gt;
Does RabbitMQ guarantee that my request reached its destination sucessfully? will it keep trying to send the request until the api responds (the api is available for exchanges) ?&lt;br&gt;
How will my application resume the execution related to the request ? my intial idea now is to isolate that code that relies on the immediate response of the external API.&lt;/p&gt;

&lt;p&gt;Is it even RabbitMQ the best choice here ?&lt;/p&gt;

&lt;p&gt;I have zero experience with RabbitMQ that's why I am still skeptical if it's appropriate in this use case so am sorry in advance if some of these questions are completly dumb.&lt;/p&gt;

&lt;p&gt;PS: we are keeping track of the timeout data.&lt;br&gt;
    The API we are connecting to is part of an external system, we have no control &lt;br&gt;
    over it.&lt;/p&gt;

</description>
      <category>help</category>
      <category>php</category>
      <category>rabbitmq</category>
      <category>requests</category>
    </item>
    <item>
      <title>what's The next step for a static React js app ?</title>
      <dc:creator>Hamida</dc:creator>
      <pubDate>Wed, 01 May 2019 09:07:14 +0000</pubDate>
      <link>https://dev.to/haamida/what-s-the-next-step-for-a-static-react-js-app-2d1i</link>
      <guid>https://dev.to/haamida/what-s-the-next-step-for-a-static-react-js-app-2d1i</guid>
      <description>&lt;p&gt;With no background in React and the so little information I have, I managed to push a static one page website.&lt;br&gt;
It's a slightly "Hello World" look alike, yet I just wanted to put it up to force myself to commit. I have a terrible case of overengineering and shiny new stuff syndroms, so please be nice in judging the code 😊😊 .&lt;br&gt;
This is the repo: &lt;a href="https://github.com/Haamida/Sneaky-React"&gt;https://github.com/Haamida/Sneaky-React&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Coming from a Symfony and php background where the front and back are tightly close, I figured that the next step for this front is to link it to a backend where we receive the reservation and newsletter inscriptions. I still have no idea how to it and still doing the research, any insights are appreciated.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>askingforhelp</category>
    </item>
  </channel>
</rss>
