You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs-src/queuing.md
+96-46Lines changed: 96 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,19 @@
1
1
# Queuing
2
2
3
-
InEngine.NET's queue functionality allows for commands to be run in the background with a simple publish/consume model.
3
+
InEngine.NET's queue functionality allows for commands to be run in the background via a [publish/subscribe](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern) model.
4
+
A command should be queued when it is desirable to run the command once, as soon as possible, in a background task.
5
+
6
+
Queuing is especially important for Web site and applications.
7
+
Queuing is like the sister technology of caching.
8
+
Caching makes page loads faster when reading data from a database, or serving static assets, by drastically reducing direct database and file system read operations.
9
+
Queuing makes page loads faster when writing data to a database, or performing other blocking tasks, by pushing them into the background.
10
+
Some common examples are sending emails, importing CSV files into a database, transforming an image file, and processing a shopping cart order.
11
+
It is not appropriate to use queuing if output from the task is needed immediately in the response of a Web request.
4
12
5
13
## Queue Drivers
6
14
7
15
To make use of queue features, a queue driver must be specified in [appsettings.json](configuration).
16
+
8
17
These are the available drivers...
9
18
10
19
### File
@@ -39,26 +48,38 @@ The sync driver causes the publish command to run a published command synchronou
39
48
All other queue commands and methods are not supported and will throw an exception if called.
40
49
This driver can be useful for plugin development and testing.
41
50
42
-
## Publishing Commands
51
+
## Enqueuing Commands
43
52
44
53
### With C# Classes
45
54
46
-
[Commands](commands) can be published programmatically with the **InEngine.Core.Queuing.Queue** class:
55
+
[Commands](commands) can be enqueued programmatically with the **InEngine.Core.Queuing.Enqueue** class:
47
56
48
57
```c#
49
-
Queue.Make().Publish(newMyCommand());
58
+
Enqueue.Command(newMyCommand())
59
+
.Dispatch();
50
60
```
51
61
52
-
Or publish to the secondary queue by passing true to the Make method:
62
+
Or enqueue to the secondary queue:
53
63
54
64
```c#
55
-
Queue.Make(true).Publish(newMyCommand());
65
+
Enqueue.Command(newMyCommand())
66
+
.ToSecondaryQueue()
67
+
.Dispatch();
56
68
```
57
69
58
-
!!! note "Do I have to use Queue.Make()?"
59
-
Queue.Make() is a factory method that autoloads the queue settings from appsettings.json, creates the appropriate queue driver, and returns an instance of Queue.
60
-
You can create your own Queue object an initialize it if you want.
61
-
At the very least you can assign the object returned by Queue.Make() to a local variable or load it into a DI container for later use.
70
+
Enqueue is just a wrapper.
71
+
It is possible to peel back the covers to get to the queue client.
72
+
```c#
73
+
// Enqueue.Command actually returns a life cycle object...
0 commit comments