cbq
2.1.0
2.1.0
  • Home
  • What's New?
  • Getting Started
    • Installation
    • Walkthrough
  • Configuration
    • Module Settings
    • Config File
      • Queue Connection
      • Worker Pool
    • Providers
      • SyncProvider
      • ColdBoxAsyncProvider
      • DBProvider
  • Jobs
    • Defining a Job
    • Creating a Job
    • Dispatching a Job
    • Working a Job
    • Failed Jobs
    • Chained Jobs
    • Batched Jobs
  • cbq Model
  • Interceptors
  • Other
    • Contributing
    • Contributors
    • Prior Art
    • Dedication
Powered by GitBook
On this page
  • Install cbq
  • Create a Queue Connection
  • Create a Worker Pool
  • Define your first Job
  • Create an instance of your Job
  • Dispatch your Job
  • Watch your job get executed
  1. Getting Started

Walkthrough

PreviousInstallationNextModule Settings

Install cbq

Refer to the section for general installation instructions as well as instructions for your specific .

Create a Queue Connection

Open up your config/cbq.cfc file and create your first Queue Connection:

component {

    function configure() {
        newConnection( "default" )
            .setProvider( "ColdBoxAsyncProvider@cbq" );
    }

}

Create a Worker Pool

Next, create a Worker Pool for your new Queue Connection. This allows our application to work the Jobs we will dispatch.

component {

    function configure() {
        newConnection( "default" )
            .setProvider( "ColdBoxAsyncProvider@cbq" );
            
        newWorkerPool( "default" )
            .forConnection( "default" );
    }

}

Define your first Job

A Job is a CFC that extends cbq.models.Jobs.AbstractJob. It can live anywhere in your application.

// models/jobs/emails/SendWelcomeEmailJob.cfc
component extends="cbq.models.Jobs.AbstractJob" {
  
    property name="userId";

    function handle() {
        log.info( "Sending a Welcome email to User ###getUserId()#" );
    
        /* sample code
      	var user = getInstance( "User" ).findOrFail( getUserId() );
      
        getInstance( "MailService@cbmailservices" )
            .newMail(
                from = "no-reply@example.com",
                to = user.getEmail(),
                subject = "Welcome!",
                type = "html"
            )
            .setView( "/_emails/users/welcome" )
            .setBodyTokens( {
                "firstName" : user.getFirstName(),
                "lastName" : user.getLastName()
            } )
            .send();
        */
    }

}

Create an instance of your Job

You can create an instance of your Job anywhere in your code — handlers, services, models, etc. Populate it with the specific data needed for this instance.

var job = getInstance( "SendWelcomeEmailJob" );
job.setUserId( newUser.getId() );

Dispatch your Job

Once your Job is created and configured, dispatch it to the Queue Connection.

job.dispatch();

Watch your job get executed

Check out LogBox to see your Job being executed. Congratulations! You've dispatched your first background Job using cbq!

Installation
provider