<?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 Mirza Rizwan on Medium]]></title>
        <description><![CDATA[Stories by Mirza Rizwan on Medium]]></description>
        <link>https://medium.com/@mirzarizwan4219?source=rss-f5cc8d8f850a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*WKFKnSvggryqLLVh</url>
            <title>Stories by Mirza Rizwan on Medium</title>
            <link>https://medium.com/@mirzarizwan4219?source=rss-f5cc8d8f850a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 16:40:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mirzarizwan4219/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[Azure Service Bus Client library used in Angular]]></title>
            <link>https://medium.com/@mirzarizwan4219/azure-service-bus-client-library-used-in-angular-80a269931006?source=rss-f5cc8d8f850a------2</link>
            <guid isPermaLink="false">https://medium.com/p/80a269931006</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[azure-service-bus]]></category>
            <dc:creator><![CDATA[Mirza Rizwan]]></dc:creator>
            <pubDate>Tue, 02 Jul 2024 06:33:16 GMT</pubDate>
            <atom:updated>2024-07-02T06:33:16.669Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will discuss how to use Azure Service Bus in Angular and how to receive messages from a queue, following the seven steps below.</p><blockquote><strong><em>Step 1: </em></strong>Install the Azure Service Bus client library.</blockquote><pre>npm install @azure/service-bus<br>npm install @types/node</pre><blockquote><strong><em>Step 2: </em></strong>Add three additional packages</blockquote><pre>npm install --save-dev os-browserify path-browserify util</pre><blockquote><strong><em>Step 3: </em></strong>Include some additional code in ‘<strong>polyfills.ts’</strong></blockquote><pre>import * as process from &#39;process&#39;;<br>(window as any).process = process;<br>(window as any)[&#39;global&#39;] = window;<br>global.Buffer = global.Buffer || require(&#39;buffer&#39;).Buffer;</pre><blockquote><strong>Step 4:</strong> Set up the paths for the installed packages in ‘<strong>tsconfig.json’</strong></blockquote><pre> &quot;compilerOptions&quot;: {<br>      &quot;skipLibCheck&quot;: true,<br>       &quot;paths&quot;: {<br>                &quot;os&quot;: [&quot;node_modules/os-browserify/browser&quot;],<br>                &quot;path&quot;: [&quot;node_modules/path-browserify&quot;],<br>                &quot;util&quot;: [&quot;node_modules/util&quot;]<br>                },<br>}<br></pre><blockquote><strong>Step 5:</strong> Develop a service within the Angular application</blockquote><pre>ng generate service azure-service-bus</pre><blockquote><strong>Step 6: </strong>Write a service to receive data from the Azure Service Bus queue</blockquote><pre>import { Injectable } from &#39;@angular/core&#39;;<br>import { ServiceBusClient, ServiceBusReceivedMessage, Receiver } from &#39;@azure/service-bus&#39;;<br>@Injectable({<br>  providedIn: &#39;root&#39;<br>})<br>export class AzureServiceBusService {<br>  private sbClient: ServiceBusClient;<br>  private testRunsReceiver: Receiver;<br><br>  constructor(private toasterService: ToasterService) {<br>    const connectionString = &#39;your-connection-string-here&#39;; // Replace with actual connection string<br>    this.sbClient = new ServiceBusClient(connectionString);<br>  }<br><br>  async receiveTestRuns() {<br>    try {<br>      const topicName = &#39;your-topic-name&#39;; // Replace with actual topic name<br>      const subscriptionId = &#39;your-subscription-id&#39;; // Replace with actual subscription ID<br><br>      this.testRunsReceiver = this.sbClient.createReceiver(topicName, subscriptionId);<br>      console.log(&#39;Receiver created:&#39;, this.testRunsReceiver);<br><br>      this.testRunsReceiver.subscribe({<br>        processMessage: async (message: ServiceBusReceivedMessage) =&gt; {<br>          console.log(&#39;Received a test run:&#39;);<br>          try {<br>            const messageBody = JSON.parse(message.body);<br>            console.log(messageBody);<br>            // Implement logic to handle the received message<br>          } catch (error) {<br>            console.error(&#39;Failed to process message body:&#39;, error);<br>            this.toasterService.ShowToastMessage(&#39;Failed to process message body&#39;, &#39;error&#39;);<br>          }<br>        },<br>        processError: async (error: any) =&gt; {<br>          console.error(&#39;Error occurred while processing messages:&#39;, error);<br>          this.toasterService.ShowToastMessage(error.message, &#39;error&#39;);<br>        }<br>      });<br><br>      // Optional: Add a check to ensure connection is alive (simple ping or similar operation)<br>    } catch (error) {<br>      console.error(&#39;Failed to set up receiver:&#39;, error);<br>     <br>    }<br>  }<br><br>  // Optional: Method to close the connection<br>  async closeConnection() {<br>    await this.sbClient.close();<br>    console.log(&#39;Service Bus connection closed.&#39;);<br>  }<br>}</pre><blockquote><strong>Step 7:</strong> Add the service injection to ‘app.component.ts’</blockquote><pre>  constructor(<br>    private azureServiceBusService: AzureServiceBusService<br>  ) { }<br>  ngOnInit(): void {<br>    this.azureServiceBusService.receiveTestRuns()<br>  }</pre><p>Following the completion of these 7 steps, we are now receiving the queue response.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80a269931006" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>