I tried to connect a Apache QPID broker with a RabbitMQ.Client (5.1.0) C#, but I got problem connection.
I am not sure that the RabbitMQ client is compatible with QPID.
The version of the protocol AMQP is 0.9
I installed a QPID server on my computer and it looks to be be functional, including the UI.
When I ran the program, the Exception I got is :
Exception message :{"None of the specified endpoints were reachable"}
The InnerException is :
"No compatible authentication mechanism found - server offered [CRAM-MD5 SCRAM-SHA-1 SCRAM-SHA-256]"
Here is the code executed:
using RabbitMQ.Client;
class Program
{
public static void Main(string[] args)
{
var factory = new ConnectionFactory()
{
HostName = "localhost",
Port = 5672,
UserName = "guest",
Password = "guest",
};
factory.Protocol = Protocols.AMQP_0_9_1;
try
{
// Cannot connect to QPID here
var connection = factory.CreateConnection();ยจ
}
catch (Exception ex)
{
// catch exception
}
}
}
1/ Does the RabbitMQ library compatible with Apache QPID broker ?
2/ If yes...from where does this authentication come from ?
Related
I am using the MQTTNet library for the MQTT connection in my application. I am using Mosquitto Broker as a MQTT broker. My app is in .Net core 3.1.
I am having requirement to send the MQTT message to device when the app is connected, normal disconnected and unexpected disconnected.
For the connected scenario, I am using the UseConnectedHandler extension method of the IMQTTClient.
mqttClient.UseConnectedHandler((MqttClientConnectedEventArgs e) =>
{
// Console.WriteLine("MqttClient - Connected");
// Publish the Connect Message
});
For the unexpected disconnect scenario I am using the WithWillMessage feature.
var mqttOptions = new ManagedMqttClientOptionsBuilder()
.WithAutoReconnectDelay(TimeSpan.FromSeconds(5))
.WithClientOptions(new MqttClientOptionsBuilder()
.WithWillMessage(_options.LastWillMessage)
.WithCleanSession()
.WithClientId(_options.DevcommMqttClientId)
.WithProtocolVersion(MqttProtocolVersion.V500)
.WithCommunicationTimeout(TimeSpan.FromSeconds(30))
.WithCredentials(_options.DevcommMqttUsername ?? string.Empty, _options.DevcommMqttPassword ?? string.Empty)
.WithTcpServer(_options.DevcommMqttHost, _options.DevcommMqttPort)
.WithTls(o =>
{
o.UseTls = _options.DevcommUseTls;
o.AllowUntrustedCertificates = _options.DevcommTlsAllowUntrustedCertificates;
o.IgnoreCertificateChainErrors = _options.DevcommTlsIgnoreCertificateChainErrors;
o.IgnoreCertificateRevocationErrors = _options.DevcommTlsIgnoreCertificateRevocationErrors;
o.SslProtocol = ParseSslProtocols(_options.DevcommTlsProtocols);
o.Certificates = _options.DevcommTlsClientCertificates.AsEnumerable();
o.CertificateValidationHandler = CertificateValidationHandler;
})
.Build())
.Build();
I am now stuck at graceful disconnect scenario. The UseDisconnectedHandler extension method is being called after the disconnect and not before disconnect.
Mosquitto broker is providing the feature of close message, which is similar of before disconnect event.
Is there anyway that using MQTTNet I can send the before disconnect message?
I tried use MQTTnet to connect mqtt.
But seems not worked, it would show the error message:
Unable to connect the remote server, the request was aborted: Could not create SSL/TLS secure channel.
I also found error message on windows event:
A fatal alert was received from the remote endpoint. The TLS protocol defined fatal alert code is 40.
using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Client.Connecting;
using MQTTnet.Client.Options;
public override void Run()
{
var option = new MqttClientOptionsBuilder()
.WithWebSocketServer("wss://mymqttserver:443")
.WithClientId(Guid.NewGuid().ToString())
.WithTls(new MqttClientOptionsBuilderTlsParameters()
{
AllowUntrustedCertificates = true,
UseTls = true,
SslProtocol = SslProtocols.Tls12,
CertificateValidationCallback = delegate { return true; },
})
.WithCleanSession()
.Build();
var mqtt = new MqttFactory().CreateMqttClient() as MqttClient;
mqtt.ConnectAsync(option).Wait();
string convertMsg = JsonConvert.SerializeObject("Mqtt Connect Successfully!!");
var appMsg = new MqttApplicationMessage();
appMsg.Payload = Encoding.UTF8.GetBytes(convertMsg);
appMsg.Topic = "myTopic";
appMsg.QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce;
appMsg.Retain = false;
mqttClient.PublishAsync(appMsg).Wait();
}
I also tried connect my mqtt server with third party application.
It can connect successfully, so my mqtt server should be okay.
But I don't know why I can't use c# to connect.
In the line
.WithWebSocketServer("wss://mymqttserver:443")
You must remove the "wss://" because that is already being specified using the method ".WithWebSocketServer". So, you would have
.WithWebSocketServer("mymqttserver:443")
Just use the server and the port.
I need an help, I can't connect with the broker.
I'm using MQTTNet library into my api project .net core
this is my code:
// GET: api/<SendCommandController>
[HttpGet]
public void Get()
{
var options = new MqttClientOptionsBuilder()
.WithTcpServer("broker.hivemq.com", 1883)
.Build();
var factory = new MqttFactory();
var mqttClient = factory.CreateMqttClient();
mqttClient.ConnectAsync(options, CancellationToken.None);
var message = new MqttApplicationMessageBuilder()
.WithTopic("Test/Mqtt")
.WithPayload("Hello World")
.WithExactlyOnceQoS()
.WithRetainFlag()
.Build();
mqttClient.PublishAsync(message, CancellationToken.None);
}
so I follow the tutorial but can't connect to broker hivemq and I can't connect to my personal broker.
So, I tested hivemq broker with mqtt.fx and works.
Only in the code the return is connected = false.
Any ideas? the error is "the client is not connected"
C# is not a language I've done much with, but I assume you are missing an await before mqttClient.ConnectAsync(options, CancellationToken.None); so the rest of the code waits for the connection to complete before trying to send the message
[HttpGet]
[Route("api/sender")]
public string Sender(string message, string hostName)
{
try
{
Send("myQ1", message, hostName);
return "successfully message sent to Queue";
}
catch (Exception ex)
{
return ex.Message;
}
}
public static void Send(string queue, string data,string hostName)
{
var factory = new ConnectionFactory() { HostName = hostName };
using (IConnection connection = factory.CreateConnection())
{
using (IModel channel = connection.CreateModel())
{
channel.QueueDeclare(queue, false, false, false, null);
channel.BasicPublish(string.Empty, queue, null, Encoding.UTF8.GetBytes(data));
}
}
}
I have configured RabbitMQ cluster on Azure AKS(Hybrid cluster Win+Linux) using helm and then deployed the above code by creating docker image using LoadBalancer Service to access the application. So, my API URL is like :
http://x.x.x.x/api/sender?message=Hi&hostname=rabbit#my-release-rabbitmq-0.my-release-rabbitmq-headless.default.svc.cluster.local
Here I am passing hostname dynamically to this API as : rabbit#my-release-rabbitmq-0.my-release-rabbitmq-headless.default.svc.cluster.local
I have port forwarded from 15672 to 3000 to access RabbitMQ Dashboard from my native computer like below image.
But not able to send the message to Queue.
So, my question is what should I pass as host name in the API I have created(above code) to send message to RabbitMQ queue
Below is my AKS cluster deployment details:
I have modified the code like:
var factory = new ConnectionFactory() { HostName = hostName, UserName="RabbitMQ Username",Password="RabitMQ Password" };
Then I passed the hostname="my-release-rabbitmq-headless";
This is the service name.
Now its working as expected.
I need to develop a WCF Hosted in a console app WebService.
I made it work using the Mutual Certificate (service and client) method using SecurityMode.Message.
But now i need to change the Security Mode to SecurityMode.Transport and use the wsHttpBinding with SSL. I made this code to host the service but i cannot get the wsdl with the browser, or execute some webmethod in the console app client.
static void Main()
{
var httpsUri = new Uri("https://localhost:8089/HelloServer");
var binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var host = new ServiceHost(typeof(WcfFederationServer.HelloWorld), httpsUri);
host.AddServiceEndpoint(typeof(WcfFederationServer.IHelloWorld), binding, "", httpsUri);
var mex = new ServiceMetadataBehavior();
mex.HttpsGetEnabled = true;
host.Description.Behaviors.Add(mex);
// Open the service.
host.Open();
Console.WriteLine("Listening on {0}...", httpsUri);
Console.ReadLine();
// Close the service.
host.Close();
}
The service is up, but i cannot get nothing on the https://localhost:8089/HelloServer.
On fiddler the get request via browser shows me this message:
fiddler.network.https> HTTPS handshake to localhost failed. System.IO.IOException
What im missing here?
Thanks
EDIT:
The Console Application Client Code
static void Main()
{
try
{
var client = new HelloWorldHttps.HelloWorldClient();
client.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.LocalMachine,
StoreName.TrustedPeople,
X509FindType.FindBySubjectName,
"www.client.com");
Console.WriteLine(client.GetData());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadKey();
}
Getting this error:
Could not establish trust relationship for the SSL/TLS secure channel
When it comes to the service, you need to map the certificate to the specific port as described here
http://msdn.microsoft.com/en-us/library/ms733791(v=vs.110).aspx
As for the client, you need to skip the verification of certificate properties like valid date, the domain by relaxing the certificate acceptance policy. An easiest way would be to accept any certiticate
ServicePointManager.ServerCertificateValidationCallback = (a,b,c,d) => true
You can finetune the acceptance callback according to the docs to best fit your needs.