<?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>Forem: Gallifrey Rules</title>
    <description>The latest articles on Forem by Gallifrey Rules (@gallifrey-rules).</description>
    <link>https://forem.com/gallifrey-rules</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%2F1981747%2Fd864d5a3-6e28-42e9-aaeb-1d3cadf59266.png</url>
      <title>Forem: Gallifrey Rules</title>
      <link>https://forem.com/gallifrey-rules</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/gallifrey-rules"/>
    <language>en</language>
    <item>
      <title>Introducing Threadosaurus: Simplify Worker Threads in Node.js with TypeScript</title>
      <dc:creator>Gallifrey Rules</dc:creator>
      <pubDate>Tue, 01 Oct 2024 16:07:37 +0000</pubDate>
      <link>https://forem.com/gallifrey-rules/introducing-threadosaurus-simplify-worker-threads-in-nodejs-with-typescript-5gj5</link>
      <guid>https://forem.com/gallifrey-rules/introducing-threadosaurus-simplify-worker-threads-in-nodejs-with-typescript-5gj5</guid>
      <description>&lt;p&gt;Managing worker threads in Node.js can be complex. That’s where &lt;strong&gt;Threadosaurus&lt;/strong&gt; comes in — a simple, intuitive library that streamlines the process of creating and running worker threads in Node.js using TypeScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Threadosaurus?&lt;/strong&gt;&lt;br&gt;
Worker threads are an essential feature in Node.js for handling CPU-intensive tasks without blocking the main event loop. However, using them can introduce challenges like managing worker creation, handling communication between main process and worker thread, timeouts, and handling errors as expected.&lt;/p&gt;

&lt;p&gt;Many other libraries rely on providing the worker thread a filename directly, which can lead to runtime errors if the path is incorrect or misconfigured. &lt;strong&gt;Threadosaurus&lt;/strong&gt; simplifies this process by automatically handling the worker class and filename setup, reducing the chances of such errors and improving code reliability.&lt;/p&gt;

&lt;p&gt;You have a single function called &lt;code&gt;CreateThreadosaurus&lt;/code&gt;, you pass on your class and that’s it! You now have an instance you can call where every method is run in a worker thread!&lt;/p&gt;

&lt;p&gt;There are some limitations which are discussed &lt;a href="https://github.com/ralphv/threadosaurus" rel="noopener noreferrer"&gt;directly in the repo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let’s see how a simple typical setup looks like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { CreateThreadosaurus } from 'threadosaurus';
import SampleWorkerThreadClass from './SampleWorkerThreadClass';

const worker = CreateThreadosaurus(SampleWorkerThreadClass);
console.log(await worker.greet('LJ and NJ'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Worker file example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Threadosaurus } from 'threadosaurus';

export default class SampleWorkerThreadClass implements Threadosaurus {
    async greet(name: string): Promise&amp;lt;string&amp;gt; {
        return Promise.resolve(`Hello ${name} from worker thread!`);
    }

    get__filename(): string {
        return __filename;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that’s it!&lt;/p&gt;

&lt;p&gt;Head &lt;a href="https://github.com/ralphv/threadosaurus" rel="noopener noreferrer"&gt;on to the repo&lt;/a&gt; to get started in no time!&lt;/p&gt;

</description>
      <category>worker</category>
      <category>workerthreads</category>
    </item>
    <item>
      <title>Quick introduction to Gallifrey-Rules</title>
      <dc:creator>Gallifrey Rules</dc:creator>
      <pubDate>Mon, 26 Aug 2024 14:58:12 +0000</pubDate>
      <link>https://forem.com/gallifrey-rules/quick-introduction-to-gallifrey-rules-2i9c</link>
      <guid>https://forem.com/gallifrey-rules/quick-introduction-to-gallifrey-rules-2i9c</guid>
      <description>&lt;p&gt;&lt;a href="https://gallifrey-rules.dev/" rel="noopener noreferrer"&gt;Gallifrey-Rules&lt;/a&gt; is an innovative Node.js/TypeScript library that streamlines the development of event-driven services, offering a powerful, structured approach to managing complex event processing workflows.&lt;/p&gt;

&lt;p&gt;Traditionally, when working with event streaming platforms like Kafka, developers often find themselves constructing multiple consumers, each tailored to connect with Kafka brokers and initiate message consumption from specific topics. Within these consumers, a core loop processes incoming messages, typically triggering a function — let’s call it &lt;code&gt;consumeMessages&lt;/code&gt;—that acts as the entry point for handling each new message. The conventional structure requires separate entry points for different consumers, driven by the distinct message types associated with each topic.&lt;/p&gt;

&lt;p&gt;However, these &lt;code&gt;consumeMessages&lt;/code&gt; functions often operate as black boxes, encapsulating large blocks of code executed per message, with little transparency into the internal processing flow. The result is an accumulation of boilerplate code that, while essential, is not directly related to the core business logic. This includes handling testing, configuration data, metrics, error management, and logging. Additionally, developers frequently face the need for mechanisms that allow consumers to enqueue new events for future processing, further complicating the codebase.&lt;/p&gt;

&lt;p&gt;As event-driven services scale alongside growing business logic, the maintenance and management of this boilerplate code can become increasingly burdensome. The complexity is further amplified when considering the requirements for properly containerizing the application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gallifrey-Rules&lt;/strong&gt; addresses these challenges head-on. This production-ready library, with design principles refined over two years of use in real-world environments, is now available as an open-source port for Node.js and TypeScript.&lt;/p&gt;

&lt;p&gt;At its core, Gallifrey-Rules enforces a streamlined and structured approach to event handling, simplifying the developer’s workflow. The library introduces three essential plugin types — &lt;strong&gt;Rules&lt;/strong&gt;, &lt;strong&gt;DataObjects&lt;/strong&gt;, and &lt;strong&gt;Actions&lt;/strong&gt; — each serving a distinct purpose in shaping your business logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rules&lt;/strong&gt;: Focus solely on business logic, dictating the actions to be taken when a new event is received.&lt;br&gt;
&lt;strong&gt;DataObjects&lt;/strong&gt;: Handle data retrieval from external sources, separating data access concerns from the business logic.&lt;br&gt;
&lt;strong&gt;Actions&lt;/strong&gt;: Manage data mutation, including adding records, modifying states, and sending notifications or emails.&lt;br&gt;
By adopting Gallifrey-Rules, developers gain several immediate benefits. The need for manually written consumers is eliminated, along with the requirement for separate entry points per topic. Gallifrey-Rules unifies all event messages into a standardized Event structure, encapsulating essential details such as &lt;code&gt;EntityName&lt;/code&gt; (e.g., orders, akin to database table names), &lt;code&gt;EventName&lt;/code&gt; (e.g., new-order or order-shipped), &lt;code&gt;EventID&lt;/code&gt; (e.g., orderId), and a &lt;code&gt;payload&lt;/code&gt; containing the event's metadata.&lt;/p&gt;

&lt;p&gt;This structured visibility allows Gallifrey-Rules to offer deep insights into the event processing flow. The library can track and measure the performance of each plugin, providing a clear overview that simplifies the troubleshooting of performance bottlenecks.&lt;/p&gt;

&lt;p&gt;Moreover, Gallifrey-Rules features centralized configuration management that abstracts underlying systems, enabling seamless transitions — such as switching from environment variables to feature flags — without the need to modify individual plugins.&lt;/p&gt;

&lt;p&gt;In addition to these capabilities, Gallifrey-Rules offers extensive error handling, recovery, and logging options, ensuring robust and resilient event-driven services.&lt;/p&gt;

&lt;p&gt;For those eager to get started, the quickest path is to explore the &lt;a href="https://github.com/ralphv/gallifrey-rules-sample/" rel="noopener noreferrer"&gt;sample application&lt;/a&gt; and consult the &lt;a href="https://gallifrey-rules.dev/docs/intro/" rel="noopener noreferrer"&gt;accompanying documentation&lt;/a&gt;. Should you have any questions or require further clarification, feel free to reach out.&lt;/p&gt;

</description>
      <category>kafka</category>
      <category>eventdriven</category>
      <category>typescript</category>
      <category>node</category>
    </item>
  </channel>
</rss>
