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

Wrong number of arguments on the handleRecoverOk override #116

Closed
jimpil opened this issue Aug 2, 2023 · 1 comment
Closed

Wrong number of arguments on the handleRecoverOk override #116

jimpil opened this issue Aug 2, 2023 · 1 comment
Milestone

Comments

@jimpil
Copy link
Contributor

jimpil commented Aug 2, 2023

Hi,

I noticed that this should take 1 argument (the consumer-tag like the rest - see here).

Moreover, this whole proxy, is the consuming hot path, and it is pretty known that proxy is a rather slow construct (albeit rather dynamic and flexible). Would you be interesting in a Java shim (see below), which does the same thing, but should be much faster? The project is already set-up with java sources so there is literally no re-arranging needed. I can send a PR if you want...

package com.novemberain.langohr;

import java.util.Map;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.impl.recovery.AutorecoveringChannel;
import com.rabbitmq.client.Consumer;
import com.rabbitmq.client.Delivery;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.ShutdownSignalException;
import com.rabbitmq.client.Envelope;
import com.rabbitmq.client.AMQP.BasicProperties;
import clojure.lang.RT;
import clojure.lang.Keyword;
import clojure.lang.IFn;

public class FnConsumer extends DefaultConsumer {

    final IFn handleConsumeOK, handleCancel, handleCancelOK, handleShutdownSignal, handleRecoverOK, handleDelivery;

    private static Channel asNonRecovering(Channel c) {
        if (c instanceof AutorecoveringChannel) {
            AutorecoveringChannel tmp = (AutorecoveringChannel) c;
            return tmp.getDelegate();
        } else
            return c;
    }

    public FnConsumer(Channel c, Map<Keyword, IFn> handlers) {

        super(asNonRecovering(c));

        handleConsumeOK = handlers.get(RT.keyword(null, "handle-consume-ok-fn"));
        handleCancel    = handlers.get(RT.keyword(null, "handle-cancel-fn"));
        handleCancelOK  = handlers.get(RT.keyword(null, "handle-cancel-ok-fn"));
        handleShutdownSignal = handlers.get(RT.keyword(null, "handle-shutdown-signal-fn"));
        handleRecoverOK = handlers.get(RT.keyword(null, "handle-recover-ok-fn"));
        handleDelivery  = handlers.get(RT.keyword(null, "handle-delivery-fn"));

    }

    @Override
    public void handleConsumeOk(String consumerTag) {
        if (handleConsumeOK != null)
            handleConsumeOK.invoke(consumerTag);
    }

    @Override
    public void handleCancelOk(String consumerTag) {
        if (handleCancelOK != null)
            handleCancelOK.invoke(consumerTag);
    }

    @Override
    public void handleCancel(String consumerTag) {
        if (handleCancel != null)
            handleCancel.invoke(consumerTag);
    }

    @Override
    public void handleRecoverOk(String consumerTag) { // this takes no args (wrongly) in the proxy-impl
        if (handleRecoverOK != null)
            handleRecoverOK.invoke(consumerTag);
    }

    @Override
    public void handleShutdownSignal(String consumerTag, ShutdownSignalException sig) {
        if (handleShutdownSignal != null)
            handleShutdownSignal.invoke(consumerTag, sig);
    }

    @Override
    public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) {
        if (handleDelivery != null)
            handleDelivery.invoke(consumerTag, envelope, properties, body);
    }

}
@michaelklishin
Copy link
Owner

Yes, please submit a PR. Thank you.

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

No branches or pull requests

2 participants