-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da18f77
commit 333edd2
Showing
12 changed files
with
124 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using RabbitMQ.Client; | ||
using RabbitMQ.Client.Events; | ||
using System.Text; | ||
using System.Text.Json; | ||
using localhands.Jobs.Models; | ||
|
||
|
||
public class JobConsumer | ||
{ | ||
private readonly string _hostname = "localhost"; // RabbitMQ host | ||
private readonly string _queueName = "job_queue"; // Queue to receive jobs | ||
|
||
public void ConsumeJobs() | ||
{ | ||
var factory = new ConnectionFactory() { HostName = _hostname }; | ||
|
||
using (var connection = factory.CreateConnection()) | ||
using (var channel = connection.CreateModel()) | ||
{ | ||
channel.QueueDeclare(queue: _queueName, durable: false, exclusive: false, autoDelete: false, arguments: null); | ||
|
||
var consumer = new EventingBasicConsumer(channel); | ||
consumer.Received += (model, ea) => | ||
{ | ||
var body = ea.Body.ToArray(); | ||
var message = Encoding.UTF8.GetString(body); | ||
var job = JsonSerializer.Deserialize<Job>(message); | ||
ProcessJob(job); | ||
}; | ||
|
||
channel.BasicConsume(queue: _queueName, autoAck: true, consumer: consumer); | ||
|
||
Console.WriteLine(" Press [enter] to exit."); | ||
Console.ReadLine(); | ||
} | ||
} | ||
|
||
private void ProcessJob(Job job) | ||
{ | ||
// Save the job for workers or notify workers | ||
// dbContext.WorkerJobs.Add(job); | ||
// dbContext.SaveChanges(); | ||
Console.WriteLine("Processed Job: " + job.Title); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using RabbitMQ.Client; | ||
using System.Text; | ||
using System.Text.Json; | ||
using localhands.Jobs.Models; | ||
|
||
public class JobProducer | ||
{ | ||
private readonly string _hostname = "localhost"; // RabbitMQ host | ||
private readonly string _queueName = "job_queue"; // Queue to send jobs | ||
|
||
public void SendJob(Job job) | ||
{ | ||
var factory = new ConnectionFactory() { HostName = _hostname }; | ||
|
||
using (var connection = factory.CreateConnection()) | ||
using (var channel = connection.CreateModel()) | ||
{ | ||
channel.QueueDeclare(queue: _queueName, durable: false, exclusive: false, autoDelete: false, arguments: null); | ||
|
||
var message = JsonSerializer.Serialize(job); | ||
var body = Encoding.UTF8.GetBytes(message); | ||
|
||
channel.BasicPublish(exchange: "", routingKey: _queueName, basicProperties: null, body: body); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
using localhands.Jobs.Models; | ||
|
||
namespace localhands.Jobs.DTOs | ||
{ | ||
public class JobDto | ||
{ | ||
public string Id { get; set; } = string.Empty; | ||
public string Title { get; set; } = string.Empty; | ||
public string Description { get; set; } = string.Empty; | ||
public string JobCategoryDto { get; set; } = string.Empty; | ||
public DateTime DatePosted { get; set; } = DateTime.Now; | ||
// public JobCategoryDto Category { get; set; } = new JobCategoryDto(); | ||
public decimal Price { get; set; } = 0; | ||
public JobPosterDto Poster { get; set; } = new JobPosterDto(); | ||
public string Zipcode { get; set; } | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,11 @@ | |
"ConnectionString": "mongodb+srv://mohammed-saalim:[email protected]/?retryWrites=true&w=majority&appName=localhandscluster", | ||
"DatabaseName": "your_database_name" | ||
}, | ||
"RabbitMQ": { | ||
"HostName": "localhost", | ||
"UserName": "guest", | ||
"Password": "guest" | ||
}, | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters