Can someone please help me to get/read the port number, hostname, channel details when i using ccdt.tab file. these details were configured in tab file. queue creation was opened successfully by using tab file but i want to get above details (connection details) using java.
I can able to get only queue manager name and queue name by using MQQueueSender.getstringproperty(); but other not able to find.
I expect port number, hostname, channel which i defined in TAB file
MQQueueConnection connection = null;
MQQueueSession session = null;
MQQueueSender sender = null;
MQQueueReceiver receiver = null;
HashMap<String, String> setValue = null;
try {
connection = getConnection(prop.getProperty("tabFilePath"));
session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
MQQueue sendQueue = (MQQueue) session.createQueue(prop.getProperty("queueName"));
sender = (MQQueueSender) session.createSender(sendQueue); System.out.println(sender.getStringProperty("XMSC_WMQ_RESOLVED_QUEUE_MANAGER"));
System.out.println(sender.getStringProperty("XMSC_WMQ_QUEUE_MANAGER"));
There is no MQ API or Class that will parse a CCDT file for an MQ application.
Set the environment variables MQCHLLIB and MQCHLTAB to point to where your CCDT file located and then use runmqsc with the '-n' parameter to have MQ manage it then issue the following MQSC command:
DIS CHL(*) ALL
Now you will have all of the details of all CLNTCONN channels from the CCDT file.
Related
I use Apache Activemq version 5.14.4 to send some messages into a queue and to read them. I want to implement a security level so as when I connect to the destination to be asked to give a username and a password.
Reading the official documentation for ActiveMQ security and looking at a lot of examples including these: example1, example2, I choose to use the Simple Authentication Plugin to achieve this.
So, in my activemq.xml, inside broker element I wrote the plugin:
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="Admin01" password="anything" groups="users,admins"/>
</users>
</simpleAuthenticationPlugin>
<authorizationPlugin>
<map>
<authorizationMap>
<authorizationEntries>
<authorizationEntry queue=">" write="producers" read="consumers" admin="admins" />
<authorizationEntry topic="ActiveMQ.Advisory.>" admin="admins" />
</authorizationEntries>
</authorizationMap>
</map>
</authorizationPlugin>
...
</broker>
Doing so, I expected to be asked about a username and a password in order to connect to a destination to consume the messages from the queue.
I create the connection and destination this way:
String username = "Admin01";
String password = "anithing"
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
factory.setTrustedPackages(Arrays.asList("myClass.package_name"));
Connection connection = null;
Session session = null;
Destination destination = null;
try {
connection = factory.createConnection(username, password);
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = session.createQueue("myQueue");
...
The ActiveMQ broker is created and when the events that I want to sent occurs, they are sent to myQueue.
(I also tryed withowt setting any username and password to the factory with factory.setPassword() and factory.setUserName() or setting the username and password only to the connection, or both and there is no exception thrown when I don't set any username and password).
Well If I want to consume the messages from the queue I intentionally not set any password and there is no exception thrown and the messages are consumed. (I expected to be thrown an exception asking for the username and password. Also I tried with wrong username and password).
private void consumeMessage() {
String userName = "Admin01";
String password = "anything";
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
// factory.setUserName(userName);
// factory.setPassword(password);
factory.setTrustAllPackages(true);
Destination destination = null;
try {
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = session.createQueue("myQueue");
consumer = session.createConsumer(destination);
consumer.setMessageListener(this);
connection.start();
}catch(JMSException e) {
e.printStackTrace();
}
}
I have overridden the credentials.properties file:
Default values:
activemq.username=system
activemq.password=manager
guest.password=password
Overridden:
activemq.username=Admin01
activemq.password=anything
I also overridden the files:
groups.properties file to admins=Admin01 and users.properties to admin=Admin01 and still no password asked.
All files mentioned above are in \apache-activemq-5.14.4\conf directory.
What can I do to implement this security level on ActiveMQ so as, when I want to connect to the destination in order to consume the messages from "myQueue" to be asked for the username and password?
By default
<simpleAuthenticationPlugin anonymousAccessAllowed="false"> deny anonymous access.
I wrote a test program based on below example to connect to service bus(1.1) installed on windows server using amqp 1.0 java api.
https://msdn.microsoft.com/en-us/library/dn574799.aspx?f=255&MSPPError=-2147217396
Everything is fine till session creation. I am getting "Peer did not create remote endpoint for link, target" exception when I tried to create MessageProducer. I used different versions of qpid-amqp-1-0(0.20 to 0.32) but the error is same.
I put some debug statements in source code of qpid-amqp and I observed SendingLinkEndPoint Target became null after few secs.
End point target: Target{address=testnamespace/testqueue}
End point target: Target{address=testnamespace/testqueue}
End point target: Target{address=testnamespace/testqueue}
End point target: Target{address=testnamespace/testqueue}
Attach{name=testnamespace/testqueue}
End point target: null
javax.jms.JMSException: Peer did not create remote endpoint for link, target: testnamespace/testqueue
RECV: com.microsoft:timeout\xa1\xbcThe operation did not complete within the allocated time 00:00:15.0675072 for object connection
I made sure the user got domain suffix as per below post
Connecting to Service Bus on Windows Server (1.1) using Java and AMQP 1.0
I enabled qpid jms debug in log4j.properties but I dont see any debug statements displayed on the console. Not sure what else I need to do to see what other user oberved(in above post).
log4j.rootLogger=TRACE, stdout
log4j.logger.org.apache.qpid.jms=DEBUG
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] - %-5p%-30.30c{1} - %m%n
the test code looks like below
String connectionString = "amqps://" + encode(userName) + ":" + encode(password) + "#" + fqdn;
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory");
env.put(Context.PROVIDER_URL, "blah.txt");
env.put("connectionfactory.ServiceBusConnectionFactory", connectionString);
Context context = null;
ConnectionFactory connectionFactory = null;
Connection connection = connectionFactory.createConnection();
System.setProperty("javax.net.ssl.trustStore","C:\\Program Files (x86)\\Java\\jre1.8.0_111\\lib\\security\\cacerts");
System.setProperty("javax.net.ssl.trustStorePassword",pwd);
Session session = null;
MessageProducer producer = null;
try
{
System.out.println("Creating session\n");
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
System.out.println("Creating Queue Impl\n");
QueueImpl queueImpl = QueueImpl.createQueue("testnamespace/testqueue");
System.out.println("Creating producer\n");
producer = session.createProducer(queueImpl);
}
catch (Exception e)`enter code here`
{
System.out.println("Exception creating session/producer\n");
return;
}
All the required ports are opened and enabled debug/trace at windows service level in event viewer but I am unable to identify whats the problem.
Any help would be greatly appreciated.
Thank you,
S.
I want to configure a Java application to work with a JMS IBM MQ queue using the bindings file.
I am using the JMSDEMO application provided by IBM.
It works with a local MQ manager but I cannot make it connect to a remote one.
I've generated the bindings file on the remote machine and copied it to my machine.
I've changed the "localhost" in the bindings file to the remote machine name.
However, the app still thinks it should connect to a local QM.
(actually it ignores the hostname settings).
Here's the IBM demo code:
public static final String cfLookup = "JMSDEMOCF";
public static final String JNDITopic = "JMSDEMOTopic";
public static final String JNDIQueue = "JMSDEMOQueue";
public static final String icf ="com.sun.jndi.fscontext.RefFSContextFactory";
........
static String url = "file:C:\\JMSDEMO\\JNDI";
..........
Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY, icf);
environment.put(Context.PROVIDER_URL, url);
ctx = new InitialDirContext( environment );
connFactory = (ConnectionFactory)ctx.lookup( cfLookup );
connection = connFactory.createConnection();
connection.start();
Here are some fragments of the bindings file (JMSDEMOCF is the name of the connection factory)
JMSDEMOCF/RefAddr/3/Content=<the remote machine name or IP; both ignored>
JMSDEMOCF/RefAddr/29/Content=<the remote machine name or IP; both ignored>(the remote port)
It also has the following line:
JMSDEMOCF/RefAddr/116/Type=XMSC_WMQ_LOCAL_ADDRESS
but deleting it changes nothing.
Create a new connection factory in your "bindings file" with MQ Explorer (why are you trying to edit the file by hand?), and specify the Transport option as MQ Client on this new connection factory (the default is Bindings, which is the local connection mode).
On the Connection tab specify the address of the QM, and on the Channels tab the server connection channel to be used to connect to the QM.
Use the new connection factory in your application when connecting from a remote host. You may need to include some additional MQ JARs in the classpath.
I have details of Host_name, Queue_name, channel_name and binding file, Except Queue_manager name. and i need to connect to MQ 7. Please just give a connectivity program. I tried posting in this and other forums but the connection problem still persists. So i thought if anyone could help me with the code. I will be very happy if anyone help me to do this.
If you know Host name, channel name and port number, then you can get the queue manager name like below:
MQEnvironment.channel = 'SYSTEM.DEF.SVRCONN'; //Replace with your channel name
MQEnvironment.hostname = 'localhost'; //Replace with your host name
MQEnvironment.port = 1414; //Replace with your port number
MQQueueManager QM_OBJ= new MQQueueManager("");
String QueueManagerName = QM_OBJ.getAttributeString(MQC.MQCA_Q_MGR_NAME, 100).trim();
Can anybody tell me how to use mstor to read mbox mail messages on windows
Thanks in advance...
An example url for accessing an mstor mailbox might be:
mstor:c:/mail on a Microsoft Windows machine
Reading messages from a local store:
Session session = Session.getDefaultInstance(new Properties());
Store store = session.getStore(new URLName("mstor:c:/mailbox/MyStore"));
store.connect();
// read messages from Inbox..
Folder inbox = store.getDefaultFolder().getFolder("Inbox");
inbox.open(Folder.READ_ONLY);
Message[] messages = inbox.getMessages();
//Remember to add the properties in above code.
this.properties = new Properties();
this.properties.setProperty("mail.store.protocol", "mstor");
this.properties.setProperty("mstor.mbox.metadataStrategy", "none");
this.properties.setProperty("mstor.mbox.cacheBuffers", "disabled");
this.properties.setProperty("mstor.mbox.bufferStrategy", "mapped");
this.properties.setProperty("mstor.metadata", "disabled");
this.properties.setProperty("mstor.mozillaCompatibility", "enbled")