Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Add support for RabbitMQ source #1911

Merged
merged 15 commits into from
Feb 8, 2024

Conversation

nitzangoldfeder
Copy link
Contributor

Hello Team

I've added support for RabbitMQ source for outgoing projects

The UI will enable to create a new pubsub called RabbitMQ / AMQP
Its required to provide shcema / host / port and queue name

  • Optional: add auth, add queue bindings

On the backend:

  • Added amqp client go internal/pkg/pubsub

Tested creation of this source on my local machine and validated that messages are being consumed on the backend

@CLAassistant
Copy link

CLAassistant commented Feb 4, 2024

CLA assistant check
All committers have signed the CLA.

- Fixed failing tests
- Fixed failing tests
- Fixed lint
- Added go_test_stub.txt
- Update required field on host and queue
Copy link
Collaborator

@subomi subomi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amqp "github.com/rabbitmq/amqp091-go"
)

var ErrInvalidCredentials = errors.New("your kafka credentials are invalid. please verify you're providing the correct credentials")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitzangoldfeder, we can remove this.

msgs, err := ch.Consume(
q.Name, // queue
"", // consumer
true, // auto-ack
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitzangoldfeder, preferably, we should ack only when we've successfully written it to our internal queue. We should do this in the for loop when reading the message.

- Fixed PR comments
- Added DLQ in case of failure
- Ack / Nack messages
- Updated UI
- Reverted api/ui/build/go_test_stub.txt
return err
}
defer ch.Close()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll also be a good idea to close conn here to as well

defer conn.Close()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitzangoldfeder We closed ch, but we didn't close conn here.

}
}

<-forever
Copy link
Collaborator

@Dotunj Dotunj Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will block forever till the process exists. I don't think you need this, since the Consume() function already runs in a goroutine.

The cancellation context is also not being used to signal to the Consume() function when to return/end so that the process can release the connection and channel resources.

One way to approach this is to check if k.ctx has been cancelled.

	for d := range msgs {
		if errors.Is(k.ctx.Err(), context.Canceled) {
			return
		}

               // rest of code
	}

And then close the connection and channel before you return from the Consume() function.

func (k *Amqp) Consume() {
	conn, err := k.dialer()
	if err != nil {
		log.WithError(err).Error("failed to instanciate a connection")
		return
	}


	ch, err := conn.Channel()
	if err != nil {
		log.WithError(err).Error("failed to instanciate a channel")
		return
	}

        defer conn.Close()
        defer ch.Close()

        // rest of code
}

- Using consume with ctx
- Checking k.ctx is error and exiting function to release connections
- Removed check for ctx in msgs loop

for d := range msgs {
ctx := context.Background()
if err := k.handler(ctx, k.source, string(d.Body)); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitzangoldfeder, we should prefer k.ctx here instead of context.Background()

return err
}
defer ch.Close()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nitzangoldfeder We closed ch, but we didn't close conn here.

@subomi
Copy link
Collaborator

subomi commented Feb 8, 2024

@Dotunj, this lgtm!, do you have any other requests?

@Dotunj
Copy link
Collaborator

Dotunj commented Feb 8, 2024

@Dotunj, this lgtm!, do you have any other requests?

LGTM

@subomi subomi merged commit aebfe9c into frain-dev:main Feb 8, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants