找不到连接URI的IConnectionFactory实现:activemq:tcp:

时间:2013-04-08 23:28:32

标签: .net connection activemq

我仍然得到“找不到连接URI的IConnectionFactory实现:activemq:tcp:// localhost:61616”错误。我已经粘贴并在编译项目中包含存档“nmsprovider-activemq.config” 我正在使用.NET 4.0,参考资料是Apache.NMS-1.5.1-bin.zip \ net-4.0 \ release

代码很简单但很简单,但我不能抛出连接错误

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apache.NMS;
using Apache.NMS.Util;
using System.Collections;
using System.Reflection;
using System.IO;


namespace ConexionActiveMQ
{
    class Program
    {
        private static string[] GetConfigSearchPaths()
        {
            ArrayList pathList = new ArrayList();

            // Check the current folder first.
            pathList.Add("");
            AppDomain currentDomain = AppDomain.CurrentDomain;

            // Check the folder the assembly is located in.

            pathList.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
            if (null != currentDomain.BaseDirectory)
            {
                pathList.Add(currentDomain.BaseDirectory);
            }

            if (null != currentDomain.RelativeSearchPath)
            {
                pathList.Add(currentDomain.RelativeSearchPath);
            }

            return (string[])pathList.ToArray(typeof(string));
        }

        static void Main(string[] args)
        {
            string[] direcciones;
            direcciones = GetConfigSearchPaths();
            // Example connection strings:
            //    activemq:tcp://localhost:61616
            //    stomp:tcp://activemqhost:61613
            //    ems:tcp://tibcohost:7222
            //    msmq://localhost

            Uri connecturi = new Uri("activemq:tcp://localhost:61616");

            Console.WriteLine("About to connect to " + connecturi);

            // NOTE: ensure the nmsprovider-activemq.config file exists in the executable folder.
            IConnectionFactory factory = new NMSConnectionFactory(connecturi);

            using (IConnection connection = factory.CreateConnection())
            using (ISession session = connection.CreateSession())
            {
                // Examples for getting a destination:
                //
                // Hard coded destinations:
                //    IDestination destination = session.GetQueue("FOO.BAR");
                //    Debug.Assert(destination is IQueue);
                //    IDestination destination = session.GetTopic("FOO.BAR");
                //    Debug.Assert(destination is ITopic);
                //
                // Embedded destination type in the name:
                //    IDestination destination = SessionUtil.GetDestination(session, "queue://FOO.BAR");
                //    Debug.Assert(destination is IQueue);
                //    IDestination destination = SessionUtil.GetDestination(session, "topic://FOO.BAR");
                //    Debug.Assert(destination is ITopic);
                //
                // Defaults to queue if type is not specified:
                //    IDestination destination = SessionUtil.GetDestination(session, "FOO.BAR");
                //    Debug.Assert(destination is IQueue);
                //
                // .NET 3.5 Supports Extension methods for a simplified syntax:
                //    IDestination destination = session.GetDestination("queue://FOO.BAR");
                //    Debug.Assert(destination is IQueue);
                //    IDestination destination = session.GetDestination("topic://FOO.BAR");
                //    Debug.Assert(destination is ITopic);

                IDestination destination = SessionUtil.GetDestination(session, "queue://FOO.BAR");
                Console.WriteLine("Using destination: " + destination);

                // Create a consumer and producer
                using (IMessageConsumer consumer = session.CreateConsumer(destination))
                using (IMessageProducer producer = session.CreateProducer(destination))
                {
                    // Start the connection so that messages will be processed.
                    connection.Start();
                    //producer.Persisten = true;

                    // Send a message
                    ITextMessage request = session.CreateTextMessage("Hello World!");
                    request.NMSCorrelationID = "abc";
                    request.Properties["NMSXGroupID"] = "cheese";
                    request.Properties["myHeader"] = "Cheddar";

                    producer.Send(request);

                    // Consume a message
                    ITextMessage message = consumer.Receive() as ITextMessage;
                    if (message == null)
                    {
                        Console.WriteLine("No message received!");
                    }
                    else
                    {
                        Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
                        Console.WriteLine("Received message with text: " + message.Text);
                    }
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:4)

您需要ActiveMQ版本的NMS库。

http://activemq.apache.org/nms/activemq-downloads.html