Junior — Middle
Have you worked with queue systems and implemented interactions through them?
sobes.tech AI
Answer from AI
Yes, I have worked with queue systems to organize asynchronous interactions between services. In projects, I used tools such as RabbitMQ and Apache Kafka.
Main use cases:
- Sending messages to a queue for background task processing.
- Ensuring reliable message delivery between microservices.
- Load distribution and scaling of processing.
Example of a simple message sender in RabbitMQ using Go:
package main
import (
"github.com/streadway/amqp"
"log"
)
func main() {
conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
if err != nil {
log.Fatal(err)
}
defer conn.Close()
ch, err := conn.Channel()
if err != nil {
log.Fatal(err)
}
defer ch.Close()
q, err := ch.QueueDeclare(
"task_queue",
true,
false,
false,
false,
nil,
)
if err != nil {
log.Fatal(err)
}
body := "Hello Queue"
err = ch.Publish(
"",
q.Name,
false,
false,
amqp.Publishing{
DeliveryMode: amqp.Persistent,
ContentType: "text/plain",
Body: []byte(body),
})
if err != nil {
log.Fatal(err)
}
log.Printf(" [x] Sent %s", body)
}
Thus, queue systems help build reliable and scalable distributed applications.