当前位置: 首页>>代码示例>>Java>>正文


Java QueueConnectionFactory类代码示例

本文整理汇总了Java中javax.jms.QueueConnectionFactory的典型用法代码示例。如果您正苦于以下问题:Java QueueConnectionFactory类的具体用法?Java QueueConnectionFactory怎么用?Java QueueConnectionFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


QueueConnectionFactory类属于javax.jms包,在下文中一共展示了QueueConnectionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSpecificConsumerRetrieval

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testSpecificConsumerRetrieval(String username, String password,
                                          String hostname, String port) throws Exception {
    String queueName = "testSpecificConsumerRetrieval";

    // Create a durable queue using a JMS client
    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder(username, password, hostname, port)
            .withQueue(queueName)
            .build();

    QueueConnectionFactory connectionFactory
            = (QueueConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    QueueConnection connection = connectionFactory.createQueueConnection();
    connection.start();

    QueueSession queueSession = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
    Queue queue = queueSession.createQueue(queueName);
    QueueReceiver receiver = queueSession.createReceiver(queue);

    HttpGet getAllConsumers = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH
                                          + "/" + queueName + "/consumers");

    CloseableHttpResponse response = client.execute(getAllConsumers);
    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK);
    String body = EntityUtils.toString(response.getEntity());

    ConsumerMetadata[] consumers = objectMapper.readValue(body, ConsumerMetadata[].class);

    Assert.assertTrue(consumers.length > 0, "Number of consumers returned is incorrect.");

    int id = consumers[0].getId();
    HttpGet getConsumer = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH + "/"
                                              + queueName + "/consumers/" + id);

    response = client.execute(getConsumer);
    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK);
    String consumerString = EntityUtils.toString(response.getEntity());
    ConsumerMetadata consumerMetadata = objectMapper.readValue(consumerString, ConsumerMetadata.class);

    Assert.assertEquals(consumerMetadata.getId().intValue(), id, "incorrect message id");

    receiver.close();
    queueSession.close();
    connection.close();
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:48,代码来源:ConsumersRestApiTest.java

示例2: testWithQueueConnectionFactoryAndJms102Usage

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
@Test
public void testWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
	QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
	QueueConnection con = mock(QueueConnection.class);

	given(cf.createQueueConnection()).willReturn(con);

	SingleConnectionFactory scf = new SingleConnectionFactory(cf);
	Connection con1 = scf.createQueueConnection();
	Connection con2 = scf.createQueueConnection();
	con1.start();
	con2.start();
	con1.close();
	con2.close();
	scf.destroy();  // should trigger actual close

	verify(con).start();
	verify(con).stop();
	verify(con).close();
	verifyNoMoreInteractions(con);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:SingleConnectionFactoryTests.java

示例3: getQueueConnection

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
public QueueConnection getQueueConnection(QueueConnectionFactory qcf)
		throws JMSException {

	final QueueConnection qc;
	final String username = Config.parms.getString("us");
	if (username != null && username.length() != 0) {
		Log.logger.log(Level.INFO, "getQueueConnection(): authenticating as \"" + username + "\"");
		final String password = Config.parms.getString("pw");
		qc = qcf.createQueueConnection(username, password);
	} else {
		qc = qcf.createQueueConnection();
	}

	return qc;

}
 
开发者ID:ot4i,项目名称:perf-harness,代码行数:17,代码来源:AbstractJMSProvider.java

示例4: initializeQueue

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
private void initializeQueue() {
    Context context = null;

    try {
        context = new InitialContext();
        final QueueConnectionFactory factory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY_NAME);
        queueConnection = factory.createQueueConnection();
        queueConnection.start();

        final Queue queue = (Queue) context.lookup(QUEUE_NAME);

        session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        sender = session.createSender(queue);
        sender.setDeliveryMode(DeliveryMode.PERSISTENT);
    } catch (NamingException | JMSException e) {
        throw new IWSException(IWSErrors.ERROR, "Queue sender (NotificationEmailSender) initialization failed.", e);
    } finally {
        close(context);
    }
}
 
开发者ID:IWSDevelopers,项目名称:iws,代码行数:21,代码来源:NotificationEmailSender.java

示例5: sendTextMessage

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
public String sendTextMessage(String queueName, String msg) throws Exception {

        if (StringUtils.isBlank(queueName)) {
            throw new IllegalArgumentException("Queue can not be null!");
        }

        if (logger.isDebugEnabled()) {

            StringBuilder sb = new StringBuilder();
            sb.append("sendTextMessage :: Setting params... \n");
            sb.append("\t- queueManagerName = '{}' \n");
            sb.append("\t- queueName = '{}' \n");
            sb.append("\t- replyToQueueName = '{}' \n");
            sb.append("\t- hostname = '{}' \n");
            sb.append("\t- port = '{}' \n");
            sb.append("\t- channel = '{}' \n");

            LoggerUtils.logDebug(logger, sb.toString(), queueManagerName, queueName, responseQueueName, hostname, port,
                channel);
        }

        QueueConnection connection = null;
        TextMessage requestMessage;
        try {

            QueueConnectionFactory qcf = new MQQueueConnectionFactory();
            ((MQQueueConnectionFactory) qcf).setIntProperty(WMQConstants.WMQ_CONNECTION_MODE,
                WMQConstants.WMQ_CM_CLIENT);
            ((MQQueueConnectionFactory) qcf).setHostName(hostname);
            ((MQQueueConnectionFactory) qcf).setPort(port);
            ((MQQueueConnectionFactory) qcf).setQueueManager(queueManagerName);
            if (StringUtils.isNotBlank(channel)) {
                ((MQQueueConnectionFactory) qcf).setChannel(channel);
            }
            // ((MQQueueConnectionFactory) qcf).setCCSID(500);

            connection = qcf.createQueueConnection(" ", " ");
            connection.start();

            // Create a session
            MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);

            // Get a request queue
            Queue queue = ((MQQueueSession) session).createQueue("queue://" + queueManagerName + "/" + queueName);

            // Create message sender
            QueueSender sender = session.createSender(queue);
            requestMessage = session.createTextMessage(msg);
            // m1.setIntProperty("JMS_", MQC.MQENC_NATIVE);

            // Setting reply-to queue
            Queue queueResp = ((MQQueueSession) session)
                .createQueue("queue://" + queueManagerName + "/" + responseQueueName);
            requestMessage.setJMSReplyTo(queueResp);
            LoggerUtils.logDebug(logger, "sendTextMessage :: message \n{}", requestMessage.toString());

            sender.send(requestMessage);
            LoggerUtils.logDebug(logger, "sendTextMessage :: Message Sent! ID: {} \n",
                requestMessage.getJMSMessageID());

            return requestMessage.getJMSMessageID();

        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (JMSException je) {
                    je.printStackTrace();
                }
            }
        }
    }
 
开发者ID:dalifreire,项目名称:mq-gateway,代码行数:73,代码来源:MQGatewayImpl.java

示例6: acknowledge

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
private void acknowledge(Message jmsMessage, String msgid) throws JMSException, ServiceLocatorException {
        QueueConnection connection = null;
        QueueSession session = null;
        QueueSender sender = null;
        try {
            Queue respQueue = (Queue) jmsMessage.getJMSReplyTo();
            QueueConnectionFactory qcf = JMSServices.getInstance().getQueueConnectionFactory(null);
            connection = qcf.createQueueConnection();
            session = connection.createQueueSession(false, QueueSession.DUPS_OK_ACKNOWLEDGE);
            sender = session.createSender(respQueue);
            Message respMsg = session.createTextMessage(msgid);
//        respMsg.setJMSCorrelationID(correlationId); not used
            sender.send(respMsg);
        } finally {
            if (sender != null) sender.close();
            if (session != null) session.close();
            if (connection != null) connection.close();
        }
    }
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:20,代码来源:InternalEventListener.java

示例7: openConnection

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
/**
 * The method overrides the one in the super class to perform
 * JMS specific functions.
 */
@Override
protected Object openConnection() throws ConnectionException {
    qConnection = null;
    qSession = null;
    queue = null;
    try {
        String server_url = this.getAttributeValueSmart(SERVER_URL);
        if ("THIS_SERVER".equals(server_url)) server_url = null;
        String queue_name = this.getQueueName();
        JMSServices jmsServices = JMSServices.getInstance();
        QueueConnectionFactory qFactory = jmsServices.getQueueConnectionFactory(server_url);
        qConnection = qFactory.createQueueConnection();
        qSession = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        qConnection.start();
        queue = jmsServices.getQueue(qSession, queue_name);
    } catch (Exception e) {
        logger.severeException("Exception in JmsAdapter.openConnection()" , e);
        throw new ConnectionException(ConnectionException.CONNECTION_DOWN, "Exception in invoking JmsAdapter" , e);

    }
    return qSession;
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:27,代码来源:JmsAdapter.java

示例8: getQueueConnectionFactory

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
/**
 * @return the jms queue connection factory
 */
public QueueConnectionFactory getQueueConnectionFactory(String contextUrl)
        throws ServiceLocatorException {
    QueueConnectionFactory factory = (QueueConnectionFactory) queueConnFactoryCache
            .get(contextUrl == null ? THIS_SERVER : contextUrl);
    if (factory == null) {
        try {
            factory = jmsProvider.getQueueConnectionFactory(namingProvider, contextUrl);
            if (contextUrl == null)
                queueConnFactoryCache.put(THIS_SERVER, factory);
            else
                queueConnFactoryCache.put(contextUrl, factory);
        }
        catch (Exception ex) {
            throw new ServiceLocatorException(-1, ex.getMessage(), ex);
        }
    }
    return factory;
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:22,代码来源:JMSServices.java

示例9: sendMessage

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
/**
 * Send a message to testInboundQueue queue
 *
 * @throws Exception
 */
private void sendMessage() throws Exception {
    InitialContext initialContext = JmsClientHelper.getActiveMqInitialContext();
    QueueConnectionFactory connectionFactory
            = (QueueConnectionFactory) initialContext.lookup(JmsClientHelper.QUEUE_CONNECTION_FACTORY);
    QueueConnection queueConnection = connectionFactory.createQueueConnection();
    QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
    QueueSender sender = queueSession.createSender(queueSession.createQueue(QUEUE_NAME));

    String message = "<?xml version='1.0' encoding='UTF-8'?>" +
            "    <ser:getQuote xmlns:ser=\"http://services.samples\" xmlns:xsd=\"http://services.samples/xsd\"> " +
            "      <ser:request>" +
            "        <xsd:symbol>IBM</xsd:symbol>" +
            "      </ser:request>" +
            "    </ser:getQuote>";
    try {
        TextMessage jmsMessage = queueSession.createTextMessage(message);
        jmsMessage.setJMSType("incorrecttype");
        sender.send(jmsMessage);
    } finally {
        queueConnection.close();
    }
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:28,代码来源:JmsTypeHeaderInboundEndpointTestCase.java

示例10: ReorderRequestMessageListener

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
public ReorderRequestMessageListener() {
    try {
        Properties properties = new Properties();
        properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF);
        properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(USERNAME, PASSWORD));
        properties.put(QUEUE_NAME_PREFIX + REORDER_REQUEST_QUEUE, REORDER_REQUEST_QUEUE);
        InitialContext ctx = new InitialContext(properties);
        // Lookup connection factory
        QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME);
        QueueConnection queueConnection = connFactory.createQueueConnection();
        queueConnection.start();
        QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        //Receive message
        Queue queue = (Queue) ctx.lookup(REORDER_REQUEST_QUEUE);
        MessageConsumer consumer = queueSession.createConsumer(queue);
        consumer.setMessageListener(this);
    } catch (NamingException | JMSException e) {
        e.printStackTrace();
    }
}
 
开发者ID:afkham,项目名称:msf4j-queueing,代码行数:21,代码来源:ReorderRequestMessageListener.java

示例11: ReorderResponseMessageListener

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
public ReorderResponseMessageListener() {
    try {
        Properties properties = new Properties();
        properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF);
        properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(USERNAME, PASSWORD));
        properties.put("queue."+ REORDER_RESPONSE_QUEUE, REORDER_RESPONSE_QUEUE);
        InitialContext ctx = new InitialContext(properties);
        // Lookup connection factory
        QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME);
        queueConnection = connFactory.createQueueConnection();
        queueConnection.start();
        queueSession =
                queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        //Receive message
        Queue queue =  (Queue) ctx.lookup(REORDER_RESPONSE_QUEUE);
        MessageConsumer consumer = queueSession.createConsumer(queue);
        consumer.setMessageListener(this);
    } catch (NamingException | JMSException e) {
        e.printStackTrace();
    }
}
 
开发者ID:afkham,项目名称:msf4j-queueing,代码行数:22,代码来源:ReorderResponseMessageListener.java

示例12: sendMessage

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
public static void sendMessage(Order order) throws NamingException, JMSException {
    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF);
    properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(USERNAME, PASSWORD));
    properties.put(QUEUE_NAME_PREFIX + REORDER_REQUEST_QUEUE, REORDER_REQUEST_QUEUE);
    InitialContext ctx = new InitialContext(properties);
    // Lookup connection factory
    QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME);
    queueConnection = connFactory.createQueueConnection();
    queueConnection.start();
    queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
    // Send message
    Queue queue = (Queue) ctx.lookup(REORDER_REQUEST_QUEUE);
    // create the message to send
    ObjectMessage message = queueSession.createObjectMessage(order);
    javax.jms.QueueSender queueSender = queueSession.createSender(queue);
    queueSender.send(message);
    queueSender.close();
    queueSession.close();
    queueConnection.close();
}
 
开发者ID:afkham,项目名称:msf4j-queueing,代码行数:22,代码来源:ReorderRequestMessageSender.java

示例13: setupJMS

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
public void setupJMS() throws NamingException, JMSException {
    InitialContext iniCtx;
    if (this.isClustered()) {
        Logger.getLogger(getClass().getName()).log(Level.INFO, "Clustered - Using HA-JMS");
        Properties p = new Properties();
        p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
        p.put(Context.PROVIDER_URL, "localhost:1100"); // HA-JNDI port.
        iniCtx = new InitialContext(p);
    } else {
        Logger.getLogger(getClass().getName()).log(Level.INFO, "Not clustered - Using non-HA JMS");
        iniCtx = new InitialContext();
    }

    QueueConnectionFactory qcf = (QueueConnectionFactory) iniCtx.lookup("ConnectionFactory");
    queue = (javax.jms.Queue) iniCtx.lookup("queue/acsQueue");
    conn = qcf.createQueueConnection();
    conn.setExceptionListener(this);
    conn.start();
    queuesession = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

    producer = queuesession.createProducer(queue);

    clear();
}
 
开发者ID:navisidhu,项目名称:libreacs,代码行数:26,代码来源:Jms.java

示例14: fireAndForget

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
protected void fireAndForget(HttpServletRequest request, HttpServletResponse response, String userMessage) {
    try {
        InitialContext ctx = new InitialContext();
        QueueConnectionFactory qconFactory = (QueueConnectionFactory) ctx.lookup(CONN_FACTORY);

        try (ConnectionContextFactory ccf = new ConnectionContextFactory(qconFactory)) {
            ProducerConnectionContext pcc = ccf.createProducerConnectionContext(new Endpoint(Endpoint.Type.QUEUE,
                    QUEUE_NAME));

            SimpleBasicMessage msg = new SimpleBasicMessage(userMessage);
            MessageId mid = new MessageProcessor().send(pcc, msg, FNF_HEADER);

            PrintWriter out = response.getWriter();
            out.println("<h1>Fire and Forget</h1>");
            out.println("<p>BasicMessage Sent [" + msg + "]</p>");
            out.println("<p>(messageId=" + mid + ")</p>");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:hawkular,项目名称:hawkular-bus,代码行数:22,代码来源:QueueSendServlet.java

示例15: rpc

import javax.jms.QueueConnectionFactory; //导入依赖的package包/类
protected void rpc(HttpServletRequest request, HttpServletResponse response, String userMessage) {
    try {
        InitialContext ctx = new InitialContext();
        QueueConnectionFactory qconFactory = (QueueConnectionFactory) ctx.lookup(CONN_FACTORY);

        ConnectionContextFactory ccf = new ConnectionContextFactory(qconFactory);
        ProducerConnectionContext pcc = ccf.createProducerConnectionContext(new Endpoint(Endpoint.Type.QUEUE,
                QUEUE_NAME));

        SimpleBasicMessage msg = new SimpleBasicMessage(userMessage);
        ListenableFuture<BasicMessageWithExtraData<SimpleBasicMessage>> future = new MessageProcessor().sendRPC(
                pcc, msg, SimpleBasicMessage.class, RPC_HEADER);
        Futures.addCallback(future, new SimpleFutureCallback());

        PrintWriter out = response.getWriter();
        out.println("<h1>RPC</h1>");
        out.println("<p>BasicMessage Sent [" + msg + "]</p>");
        out.println("<p>Check server logs for response.</p>");

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:hawkular,项目名称:hawkular-bus,代码行数:24,代码来源:QueueSendServlet.java


注:本文中的javax.jms.QueueConnectionFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。