Code Monkey home page Code Monkey logo

Comments (4)

mjeremym avatar mjeremym commented on June 17, 2024

Tried this myself and I get an Unsupported exception. Not all JMS API was implemented. Will have a look into it.

from jeromq-jms.

mueller-jens avatar mueller-jens commented on June 17, 2024

I have overridden the ZmqConnectionFactory and the ZmQConnection to overcome this:

ZmqConnectionFactory:

public class ZmqConnectionFactory extends org.zeromq.jms.ZmqConnectionFactory {

    private final Map<String, ZmqURI> destinationSchema = new HashMap<String, ZmqURI>();
    private String gatewayFactoryClassName = ZmqGatewayFactory.class.getCanonicalName();
    private String[] packageNameExtensions = null;

    /**
     * Construct Zero MQ connection factory.
     */
    public ZmqConnectionFactory() {
        super();
    }

    /**
     * Construct Zero MQ connection factory with the specified destination URIs.
     * @param destinations  the destination URIs
     */
    public ZmqConnectionFactory(final String[] destinations) {
        super(destinations);
    }

    /**
     * Construct Zero MQ connection factory with the specified destination URIs.
     * @param gatewayFactoryClassName  the class name of the gateway factory
     * @param packageNameExtensions    the array of packages containing extension to ZERO MQ
     * @param destinations             the destination URIs
     */
    public ZmqConnectionFactory(final String gatewayFactoryClassName, final String[] packageNameExtensions, final String[] destinations) {
        super(gatewayFactoryClassName, packageNameExtensions, destinations);
        this.gatewayFactoryClassName = gatewayFactoryClassName;
        this.packageNameExtensions = packageNameExtensions;

    }

    /**
     * @return               return a factory gateway
     * @throws ZmqException  throws exception when factory construction fails
     */
    private ZmqGatewayFactory getFactoryGateway() throws ZmqException {
        try {
            @SuppressWarnings("unchecked")
            final Class<? extends ZmqGatewayFactory> gatewayFactoryClass = (Class<? extends ZmqGatewayFactory>) Class
                    .forName(gatewayFactoryClassName);

            final Constructor<?> gatewayFactoryConstructor = gatewayFactoryClass.getConstructor(String[].class, Map.class);

            final ZmqGatewayFactory gatewayFactory = (ZmqGatewayFactory) gatewayFactoryConstructor.newInstance(packageNameExtensions,
                    destinationSchema);

            return gatewayFactory;
        } catch (ClassNotFoundException ex) {
            throw new ZmqException("Class could not be found.", ex);
        } catch (NoSuchMethodException | SecurityException ex) {
            throw new ZmqException("Unable to find required constructor for class: " + gatewayFactoryClassName, ex);
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            throw new ZmqException("Unable to invoke constructor for class: " + gatewayFactoryClassName, ex);
        }

    }

    @Override
    public QueueConnection createQueueConnection(final String userName, final String password) throws JMSException {
        ZmqGatewayFactory gatewayFactory = getFactoryGateway();
        QueueConnection connection = new ZmqConnection(gatewayFactory, destinationSchema);

        return connection;
    }

    @Override
    public TopicConnection createTopicConnection() throws JMSException {
        return createTopicConnection(null, null);
    }

    @Override
    public TopicConnection createTopicConnection(final String userName, final String password) throws JMSException {

        ZmqGatewayFactory gatewayFactory = getFactoryGateway();
        TopicConnection connection = new ZmqConnection(gatewayFactory, destinationSchema);

        return connection;
    }

    @Override
    public JMSContext createContext() {

       return createContext(null, null, ZmqSession.AUTO_ACKNOWLEDGE);
    }

    @Override
    public JMSContext createContext(final int sessionMode) {

           return createContext(null, null, sessionMode);
    }

    @Override
    public JMSContext createContext(final String userName, final String password) {

           return createContext(userName, password, ZmqSession.AUTO_ACKNOWLEDGE);
    }

    @Override
    public JMSContext createContext(final String userName, final String password, final int sessionMode) {

        try {
            ZmqGatewayFactory gatewayFactory = getFactoryGateway();
            ZmqConnection connection = new ZmqConnection(gatewayFactory, destinationSchema);

            ZmqJMSContext context = new ZmqJMSContext(connection, sessionMode);

            return context;
        } catch (ZmqException ex) {
            throw new JMSRuntimeException("Unable to create context.", ex.getErrorCode(), ex);
        }
    }

ZmqConnection:

public class ZmqConnection extends org.zeromq.jms.ZmqConnection {

    public ZmqConnection(ZmqGatewayFactory gatewayFactory, Map<String, ZmqURI> destinationSchema) {
        super(gatewayFactory, destinationSchema);
        // 
    }

    
    @Override
    public void start() throws JMSException {
    }

    @Override
    public void stop() throws JMSException {
    }
    
    
    @Override
    public void close() throws JMSException {
    }
}

from jeromq-jms.

mjeremym avatar mjeremym commented on June 17, 2024

from jeromq-jms.

mjeremym avatar mjeremym commented on June 17, 2024

Fixed in release 3.0

from jeromq-jms.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.