The goal is to connect to Azure IoT Hub using Qpid jms client.
I am getting error as "javax.jms.JMSSecurityException: Received error from
remote peer without description [condition = amqp:unauthorized-access]"
I have tried below code
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for
full license information.
import com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Hashtable;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
public class JmsTopicQuickstart2 {
// number of messages to send
private static int totalSend = 1;
public void run(String connectionString) throws Exception {
// The connection string builder is the only part of the
azure-servicebus SDK library
// we use in this JMS sample and for the purpose of robustly parsing
the Service Bus
// connection string.
ConnectionStringBuilder csb = new
ConnectionStringBuilder(connectionString);
// set up the JNDI context
Hashtable<String, String> hashtable = new Hashtable<>();
hashtable.put("connectionfactory.SBCF",
"amqps://xxxxx.azure-devices.net?amqp.idleTimeout=120000");
hashtable.put("topic.TOPIC", "devices/device001/messages/events");
hashtable.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.qpid.jms.jndi.JmsInitialContextFactory");
Context context = new InitialContext(hashtable);
ConnectionFactory cf = (ConnectionFactory) context.lookup("SBCF");
// Look up the topic
Destination topic = (Destination) context.lookup("TOPIC");
// we create a scope here so we can use the same set of local
variables cleanly
// again to show the receive side seperately with minimal clutter
{
// Create Connection
Connection connection = cf.createConnection(csb.getSasKeyName(),
csb.getSasKey());
connection.start();
System.out.println("Started");
// Create Session, no transaction, client ack
Session session = connection.createSession(false,
Session.CLIENT_ACKNOWLEDGE);
// Create producer
MessageProducer producer = session.createProducer(topic);
// Send messaGES
for (int i = 0; i < totalSend; i++) {
BytesMessage message = session.createBytesMessage();
message.writeBytes(String.valueOf(i).getBytes());
producer.send(message);
System.out.printf("Sent message %d.\n", i + 1);
}
producer.close();
session.close();
connection.stop();
connection.close();
}
}
public static void main(String[] args) {
//System.exit(runApp(args, (connectionString) -> {
JmsTopicQuickstart2 app = new JmsTopicQuickstart2();
String
connectionString="HostName=xxxx.azure-devices.net;DeviceId=device001;SharedAccessKey=XXXX";
try {
app.run(connectionString);
//return 0;
} catch (Exception e) {
System.out.printf("%s", e.toString());
System.out.println("\n"+e.getLocalizedMessage());
// return 1;
}
//}));
}
}
Can someone help me with this?
--
Sent from:
http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html---------------------------------------------------------------------
To unsubscribe, e-mail:
[hidden email]
For additional commands, e-mail:
[hidden email]