Skip to content

Warning

This document is for advanced users and it's also non-essentials to use our script. But if you'd like to learn about this module be our guest.

FiveMQ

We recreated a RabbitMQ like system so we can send tasks through a FiveM compatible broker system.

Critical

FiveMQ events in our scripts should NOT be called BY A THRID PARTY AT ALL !

Events and callbacks

All events are always called from server script to server script.

All first arguments of FiveMQ events is a callback with acknowledgement.

When a job has timed out or the ack is false the job will be requeued and will be triggered 5 minutes from then.

Returns: void

Callback arguments

Argument Type Description
ack Boolean Message acknowledgement, True is the message has been processed, False if the message could not be processed.
Acknowledgement must been given within 60 seconds otherwise the job is seen as timed out.

Everything after the first argument are event specific arguments. See the documentation of specific FiveMQ events for more info.

Example (server side)

AddEventHandler("FiveMQEventName", function(cb, ...)
  -- Your code here when done run:
  cb(true)

  -- Unless something went wrong and you can't process the message you would run:
  cb(false)
end)
on("FiveMQEventName", (cb, ...args) => {
  // Your code here when done run:
  cb(true)

  // Unless something went wrong and you can't process the message you would run:
  cb(false)
})
on("FiveMQEventName", (cb: ((ack: boolean) => void), ...args: any[]) => {
  // Your code here when done run:
  cb(true)

  // Unless something went wrong and you can't process the message you would run:
  cb(false)
})

FiveMQExports

In our core object there is the GetJobQueueSystem which give you the FiveMQ function that you can call to manage your own FiveMQ messages.

start

This starts the FiveMQ process. This is also triggered when calling addJob.

Returns: void

Example

-- Get core object
local CoreObject = export["rn-bridge"]:GetCoreObject()

-- Get FiveMQ bridge
local FiveMQ = CoreObject.GetJobQueueSystem()

FiveMQ.start()
// Get core object
const CoreObject = export["rn-bridge"].GetCoreObject()

// Get FiveMQ bridge
const FiveMQ = CoreObject.GetJobQueueSystem()

FiveMQ.start()
import type { BridgeExport } from "@rn/lib_server";

// Get core object
const CoreObject = (export["rn-bridge"] as BridgeExport).GetCoreObject()

// Get FiveMQ bridge
const FiveMQ = CoreObject.GetJobQueueSystem()

FiveMQ.start()

stop

This stops the FiveMQ process. This is also triggered when calling deleteJob if there are no jobs left.

Returns: void

Example

-- Get core object
local CoreObject = export["rn-bridge"]:GetCoreObject()

-- Get FiveMQ bridge
local FiveMQ = CoreObject.GetJobQueueSystem()

FiveMQ.stop()
// Get core object
const CoreObject = export["rn-bridge"].GetCoreObject()

// Get FiveMQ bridge
const FiveMQ = CoreObject.GetJobQueueSystem()

FiveMQ.stop()
import type { BridgeExport } from "@rn/lib_server";

// Get core object
const CoreObject = (export["rn-bridge"] as BridgeExport).GetCoreObject()

// Get FiveMQ bridge
const FiveMQ = CoreObject.GetJobQueueSystem()

FiveMQ.stop()

addJob

To create a new job you call this function with the minimal job data.

Returns: Promise<boolean> Success boolean

Arguments

Argument Type Description
job JobQueueModelMinimal Data of the new job.

Example

-- Get core object
local CoreObject = export["rn-bridge"]:GetCoreObject()

-- Get FiveMQ bridge
local FiveMQ = CoreObject.GetJobQueueSystem()

-- NOTE: os.time doesn't return milleseconds so we make it milleseconds.
FiveMQ.addJob({
  eventName = "YourEventName",
  triggerAt = os.time() * 1000 + (1000 * 60 * 5), -- In 5 minutes
  args = {"arg1", 69, false}, -- Your arguments
  receivingResourceName = GetCurrentResourceName(),
  tpIdentifier = "YourCustomIdentifierIfYouWant" -- optional
})
// Get core object
const CoreObject = export["rn-bridge"].GetCoreObject()

// Get FiveMQ bridge
const FiveMQ = CoreObject.GetJobQueueSystem()

await FiveMQ.addJob({
  eventName: "YourEventName",
  triggerAt: Date.now() + (1000 * 60 * 5), // In 5 minutes
  args: ["arg1", 69, false], // Your arguments
  receivingResourceName: GetCurrentResourceName(),
  tpIdentifier: "YourCustomIdentifierIfYouWant" // optional
})
import type { BridgeExport } from "@rn/lib_server";

// Get core object
const CoreObject = (export["rn-bridge"] as BridgeExport).GetCoreObject()

// Get FiveMQ bridge
const FiveMQ = CoreObject.GetJobQueueSystem()

await FiveMQ.addJob({
  eventName: "YourEventName",
  triggerAt: Date.now() + (1000 * 60 * 5), // In 5 minutes
  args: ["arg1", 69, false], // Your arguments
  receivingResourceName: GetCurrentResourceName(),
  tpIdentifier: "YourCustomIdentifierIfYouWant" // optional
})

deleteJob

To delete a job you call this function with the a database id or tpIdentifier.

Returns: Promise<boolean> Success boolean

Arguments

Argument Type Description
idOrTPIdentifier Number | String The database id or tpIdentifier of the job

Example

-- Get core object
local CoreObject = export["rn-bridge"]:GetCoreObject()

-- Get FiveMQ bridge
local FiveMQ = CoreObject.GetJobQueueSystem()

FiveMQ.deleteJob("YourCustomIdentifierOrDatabaseId")
// Get core object
const CoreObject = export["rn-bridge"].GetCoreObject()

// Get FiveMQ bridge
const FiveMQ = CoreObject.GetJobQueueSystem()

await FiveMQ.deleteJob("YourCustomIdentifierOrDatabaseId")
import type { BridgeExport } from "@rn/lib_server";

// Get core object
const CoreObject = (export["rn-bridge"] as BridgeExport).GetCoreObject()

// Get FiveMQ bridge
const FiveMQ = CoreObject.GetJobQueueSystem()

await FiveMQ.deleteJob("YourCustomIdentifierOrDatabaseId")

isJobPending

To check if a job is pending you call this function with a database id or tpIdentifier.

Returns: Promise<boolean> If the job is pending or not

Arguments

Argument Type Description
idOrTPIdentifier Number | String The database id or tpIdentifier of the job

Example

-- Get core object
local CoreObject = export["rn-bridge"]:GetCoreObject()

-- Get FiveMQ bridge
local FiveMQ = CoreObject.GetJobQueueSystem()

local IdOrIdentifier = "YourCustomIdentifierOrDatabaseId"
if FiveMQ.isJobPending(IdOrIdentifier) then
  print("We are still waiting on job '"..tostring(IdOrIdentifier).."'...")
end
// Get core object
const CoreObject = export["rn-bridge"].GetCoreObject()

// Get FiveMQ bridge
const FiveMQ = CoreObject.GetJobQueueSystem()

const IdOrIdentifier = "YourCustomIdentifierOrDatabaseId"
if (await FiveMQ.isJobPending(IdOrIdentifier)) {
  console.log(`We are still waiting on job '${IdOrIdentifier}'...`)
}
import type { BridgeExport } from "@rn/lib_server";

// Get core object
const CoreObject = (export["rn-bridge"] as BridgeExport).GetCoreObject()

// Get FiveMQ bridge
const FiveMQ = CoreObject.GetJobQueueSystem()

const IdOrIdentifier = "YourCustomIdentifierOrDatabaseId"
if (await FiveMQ.isJobPending(IdOrIdentifier)) {
  console.log(`We are still waiting on job '${IdOrIdentifier}'...`)
}