I’m new to rabbitmq but I have to connect to remote broker to send and receive messages. Remote server is out of my control and it’s almost impossible to get answers from its team. Nevertheless, I have address, port, virtual host and user credentials at my disposal. Server uses TLS v1.2.
The problem is I cannot establish connection to the server with .NET client. Client is “rabbitmq.client.5.1.0”, .NET Framework 4.5.1 and VS 2017. My code is:
public bool Start() {
try {
var f = new ConnectionFactory();
f.UserName = "TestUser";
f.Password = "TestPwd";
f.HostName = "x.x.x.x";
f.Port = 5673;
f.VirtualHost = "TestVH";
f.Ssl.Version = SslProtocols.Tls12;
f.Ssl.Enabled = true;
f.Ssl.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateChainErrors
| SslPolicyErrors.RemoteCertificateNameMismatch
| SslPolicyErrors.RemoteCertificateNotAvailable;
var c = f.CreateConnection();
} catch( Exception e ) {
throw e;
}
}
It throws an exception which innermost is:
Authentication failed because the remote party has closed the transport stream.
(Wireshark capture).
If I do it with Java (1.8, amqp-client-4.0.2), I can successfully connect to the server.
public static void main( String[] args ) throws Exception{
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("x.x.x.x");
factory.setPort(5673);
factory.setUsername( "TestUser" );
factory.setPassword( "TestPwd" );
factory.setVirtualHost( "TestVH" );
factory.useSslProtocol("TLSv1.2");
Connection conn = factory.newConnection();
}
Wireshark capture
I would like to use C# to get the job done but I can not sort this thing out. Any help would be greatly appreciated!
try changing this line:
f.Ssl.Version = SslProtocols.Tls12;
to this:
f.Ssl.Version = SslProtocols.Tls12 | SslProtocols.Ssl3 | SslProtocols.Tls11 | SslProtocols.Ssl2;
If that works then you narrow them down
Related
In the internals of an ContextListener how can I find out the port the Web App is running on
I have a Java Web app project with JSP pages as frontend. The project implements a ServletContextListener to connect to the backend. This ContextListener accesses the database by instantiating an access class DBQuery in its contextInitialized method:
ServletContext ctx = contextEvent.getServletContext();
dbQuery = new DBQuery();
ctx.setAttribute("dbQuery", dbQuery);
The JSP pages then refer to this DBQuery object via
getServletContext().getAttribute("dbQuery");
and call the methods of DBQuery as they desire.
Now the problem: In the DBQuery class I need to do different things depending on which host and on which port the web app runs.
I found a way to determine the host name in DBQuery:
import java.net.InetAddress;
String hostName = InetAddress.getLocalHost().getHostName();
Strangely InetAddress does not seem to have a method to get the port number. How can I find out in the DBQuery class on which the port the web app runs on?
Following Steve's comment to look at a GitHub gist, I came up with the following adapted code which does exactly what was asked for:
String port = "80";
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objs = mbs.queryNames( new ObjectName( "*:type=Connector,*" ),
Query.match( Query.attr( "protocol" ), Query.value( "HTTP/1.1" ) ) );
for ( ObjectName obj : objs ) {
String scheme = mbs.getAttribute( obj, "scheme" ).toString();
port = obj.getKeyProperty( "port" );
break;
}
} catch ( MalformedObjectNameException | UnknownHostException | MBeanException | AttributeNotFoundException | InstanceNotFoundException | ReflectionException ex ) {
ex.printStackTrace();
}
So the main thing is to instantiate a MBeanServer and utilise its attributes.
I am developing a Spring-Boot project which also includes a socketIO server based on netty-socket Io. And therefore two clients: a web client and an android client!
all of them work wonderfully locally! But when I deploy online server in Jelastic only the web client which accesses netty-SocketIO server, but android client fails to connect to netty-SocketIO server. someone could help me configure the netty-socketIO server to accept all requests from any address on port 8888
Server configuration
Configuration config = new Configuration();
//config.setHostname("sec.j.layershift.co.uk");
config.setHostname("0.0.0.0");
config.setPort(8888);
final SocketIOServer server = new SocketIOServer(config);
// Listen for client connections
server.addConnectListener(client -> {
System.out.println("************ Client: " + getIpByClient(client) + " Connected ************");
});
Web client configuration
#CrossOrigin("*")
#RestController
public class ClientLocation {
Socket socket =null;
EventBuilder eventBuilder =null;
Gson gs = new Gson();
//................................
socket = IO.socket("http://sec.j.layershift.co.uk:8888");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
#Override
public void call(Object... args) {
ChatObject co = new ChatObject("ADMIN", "");
String infUser = gs.toJson(co);
System.out.println("\n"+infUser);
JSONObject jb = new JSONObject();
try {
// jb.put("userName", co.getUserName());
// jb.put("message", co.getMessage());
jb = new JSONObject(infUser);
socket.emit("username", jb);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Configuration of the java or android client
private void clientIO(){
try {
socket = IO.socket("http://aug-sec.j.layershift.co.uk:8888");
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
Nb. the configuration of the java or android client is identical to that of the web because all use the Socket.IO v1.0.0. But only the web client works from the Jelastic host because it is in the same folder as the server and the java clients do not succeed, so everything works in localhost or in LAN
There are 2 possible solutions
You can use the public IP (the way suggested by #Ruslan)
Also, the Jelastic platform resolver supports the WebSocket proxying (if the "Upgrade: websocket" header is present). You can use the JELASTIC_EXPOSE variable to forward the requests from port 80 to 8888 (more info here https://docs.jelastic.com/container-ports/#ports-auto-redirect) inside your container and then just access the app by your environment domain and port 80
In a Java client app we are connecting to a multi-instance MQ Manager as follows:
java.net.URL ccdt = new URL("file:./config/qmgrs/MQMGR/AMQCLCHL.TAB");
MQQueueManager mqQueueManager = new MQQueueManager("*MQMGR", ccdt);
We can then for example enquire about the current depth of a queue as follows:
int openOptions = CMQC.MQOO_INQUIRE;
MQQueue mqQueue = mqQueueManager.accessQueue("A.QUEUE.NAME", openOptions);
System.out.println("queue depth:" + mqQueue.getCurrentDepth());
Question is, using the same MQQueueManager object, how can we get the list of multi-instance MQ Managers' addresses and ports. Or any other info about the manager itself...
We can see there is the following sort of thing available:
String nameList = mqQueueManager.getAttributeString(MQConstants.MQCA_NAMELIST_NAME, MQConstants.MQ_NAMELIST_NAME_LENGTH);
But when we call the above command, we get:
com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2067'.
We are not sure if this is because the client code is not configured correctly or, if it is because the connection that we are using does not have sufficient permissions to get information about the manager?
You will have to use MQ PCF classes to query queue manager attributes. There is sample PCF_WalkThroughQueueManagerAttributes.java shipped with MQ that displays all attributes of queue manager. Here is small sample that lists local queues of a queue manager.
private void runPCFTest() {
try {
PCFAgent agent = new PCFAgent(connect());
PCFParameter[] parameters = { new MQCFST (MQConstants.MQCA_Q_NAME, "*"),
new MQCFIN (MQConstants.MQIA_Q_TYPE, MQConstants.MQQT_LOCAL)};
MQMessage[] responses = agent.send(CMQCFC.MQCMD_INQUIRE_Q_NAMES, parameters);
MQCFH cfh = new MQCFH(responses[0]);
for (int i = 0; i < cfh.getParameterCount(); i++) {
System.out.println (PCFParameter.nextParameter (responses [0]));
}
}catch(Exception ex) {
System.out.println(ex);
}
}
#SuppressWarnings({ "unchecked", "rawtypes" })
private MQQueueManager connect() throws MQException {
Hashtable props = new Hashtable();
props.put(MQConstants.HOST_NAME_PROPERTY, "localhost");
props.put(MQConstants.PORT_PROPERTY, 1414);
props.put(MQConstants.CHANNEL_PROPERTY, "MFT_CHN");
props.put(MQConstants.USER_ID_PROPERTY, "user1");
props.put(MQConstants.PASSWORD_PROPERTY, "passw0rd");
props.put(MQConstants.USE_MQCSP_AUTHENTICATION_PROPERTY, true);
return new MQQueueManager("MQM", props);
}
But why do you want to query connection information, host, port etc?
If I understand your question correctly, you want to know all of the hostnames (or IP addresses) and Port numbers of the servers where the MI queue manager may reside. Correct?
This information is in your CCDT file. When you (or MQAdmin) created your CCDT entry for the CLNTCONN (client-side channel), you would have issued a like:
DEFINE CHANNEL(TEST.CHL) CHLTYPE(CLNTCONN) TRPTYPE(TCP) CONNAME('ipaddr1(1414), ipaddr2(1414)') QMNAME(QM1)
Hence, the CONNAME parameter has the information and that is what the MQ client library uses to connect to the remote queue manager. First it will try 'ipaddr1(1414)' and if it fails then it will try 'ipaddr2(1414)'.
I am developing the web service where in I want to connect to the SOA server. It's giving connection exception.
Code:
public class ConnectSOA{
public static void main(String[] args){
Map<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String> connProperties = new HashMap<IWorkflowServiceClientConstants.CONNECTION_PROPERTY, String>();
connProperties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,WorkflowServiceClientFactory.REMOTE_CLIENT);
connProperties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,"t3://10.10.78.79:8001");
connProperties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
try {
workflowServiceClient = WorkflowServiceClientFactory
.getWorkflowServiceClient(connProperties, null, null);
itaskQueryService = workflowServiceClient.getTaskQueryService();
statePredicate = new Predicate(
TableConstants.WFTASK_STATE_COLUMN, Predicate.OP_EQ,
IWorkflowConstants.TASK_STATE_ASSIGNED);
iworkFlowContext = itaskQueryService.authenticate("demouser","demo1".toCharArray(), null);
} catch(Exception e ){
e.printStackTrace();
}
}
}
Exception :
java.net.ConnectException: t3://10.10.78.79:8001 Bootstrap to: hostname/'10.10.78.79:8001' over: 't3' got an error or timed out
I have check the soa server its up and running on the machine.
Can you ping your weblogic?
java weblogic.Admin -url t3://IP:8001 -username xxx -password xxx PING 10
I see that you have 10.10.78.79:8001 and in Exception IP:8001
Could be that your server is not ok. Check the config. See your config.xml and what the listen address for the server is and verify that you can ping it.
I'm trying to use thrift to relalize communication between nodejs client and Java server
Thrift offer different kinds of java server which have been implemented
· TSimpleServer
· TNonblockingServer
· THsHaServer
· TThreadedSelectorServer
· TThreadPoolServer
I have successfully used nodejs client to call the function in TTSimpleServer and TThreadPoolServer which both use TServerSocket to initialize
TServerSocket serverTransport = new TServerSocket(9090);
CalculatorService.Processor<CalculatorImpl> processor = new CalculatorService.Processor<CalculatorImpl>(
new CalculatorImpl());
TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport).processor(processor);
args.maxWorkerThreads(100);
TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(
serverTransport).processor(processor));
System.out.println("Starting server on port 9090 ...");
server.serve();
but when I try to use TNonblockingServer,TThreadedSelectorServer and THaHsServer , I came acrross following error in nodejs client
{ [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }
I realized that this may be caused by TNonblockingSocket, is there any method to use nodejs communicate with TNonblockingSocket
try
{
TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(
9090);
CalculatorService.Processor<CalculatorImpl> processor = new CalculatorService.Processor<CalculatorImpl>(
new CalculatorImpl());
TServer server = new TThreadedSelectorServer(new TThreadedSelectorServer.Args(
serverTransport).processor(processor));
System.out.println("Starting server on port 9090 ...");
server.serve();
} catch (TTransportException e)
{
e.printStackTrace();
}
my nodejs client code is as follow
var thrift = require('thrift');
var ThriftTransports = require('thrift/transport');
var ThriftProtocols = require('thrift/protocol');
var Calculator = require('./gen-nodejs/CalculatorService.js');
var ttypes = require('./gen-nodejs/tutorial_types');
transport = ThriftTransports.TFramedTransport();
protocol = ThriftProtocols.TBinaryProtocol();
var connection = thrift.createConnection("localhost", 9090, {
transport : transport,
protocol : protocol
});
connection.on('error', function(err) {
console.log(err)
});
// Create a Calculator client with the connection
var client = thrift.createClient(Calculator, connection);
client.send_print(1,1, function(err, response) {
console.log("send_print result:" + response);
});
Well , I just found the answer
This problem is truly caused by TTFramedTransport
i found even when I use this in my code
transport = ThriftTransports.TFramedTransport();
the transport seems not successfully been assigned TFramedTransport
I just try this way
transport = require('./node_modules/thrift/framed_transport.js')
it succeeded
I am not familiar with node.js , maybe I figure out why this happen later