ActiveMQ Java Broker, Python Client - java

I have for legacy reasons a Java activeMQ implementation of the Broker/Publisher over vanilla tcp transport protocol. I wish to connect a Python client to it, however all the "stomp" based documentation doesn't seem to have it, not over the stomp protcol, and when I try the basic examples I get the error on the Java Broker side:
[ActiveMQ Transport: tcp:///127.0.0.1:62860#5001] WARN org.apache.activemq.broker.TransportConnection.Transport - Transport Connection to: tcp://127.0.0.1:62860 failed: java.io.IOException: Unknown data type: 80
The Broker code is very vanilla in Java:
String localVMurl = "vm://localhost";
String remoterURL = "tcp://localhost:5001";
BrokerService broker = new BrokerService();
broker.addConnector(localVMurl);
broker.addConnector(remoterURL);
broker.setAdvisorySupport(true);
broker.start();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(localVMurl+"?create=false");
Connection connection = connectionFactory.createConnection();
and the Python just fails. I can't seem to find anything online using just basic "tcp://localhost:" connections from Python. Am I doing something wrong here?
import stomp
class MyListener(stomp.ConnectionListener):
def on_error(self, headers, message):
print('received an error "%s"' % message)
def on_message(self, headers, message):
print('received a message "%s"' % message)
conn = stomp.Connection(host_and_ports = [('localhost', 5001)])
conn.start()
conn.connect('admin', 'password', wait=True)
and I get the error:
IndexError: list index out of range

Without seeing the broker configuration it is a bit tricky to answer but from the error I'd guess you are trying to connect a STOMP client to the OpenWire transport which won't work, you need to have a STOMP TransportConnector configured on the broker and point the STOMP client there.
See the ActiveMQ STOMP documentation.
To add STOMP support for an embedded broker you'd do something along the lines of:
brokerService.addConnector("stomp://0.0.0.0:61613");

Related

Java WSS Connection Could not create transport exception

I'm so stuck about this.
I want to subscribe an ActiveMQ topic. ActiveMQ works on Centos machine, NOT LOCALHOST. I can consume messages with tcp, http protocols. Code;
public static void main(String[] args) throws JMSException {
PropertyUtils.loadPropertyFile();
Properties receiverProperties = PropertyUtils.getreceiverProperties();
// URL of the JMS server
String url = (String) receiverProperties.get("receiver.connection.url");
// Name of the queue we will receive messages from
String subject = (String) receiverProperties.get("receiver.topic.name");
// Getting JMS connection from the server
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
Connection connection = connectionFactory.createConnection();
connection.start();
// Creating session for getting messages
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Getting the topic
Destination destination = session.createTopic(subject);
// MessageConsumer is used for receiving (consuming) messages
MessageConsumer consumer = session.createConsumer(destination);
Message message = null;
// Here we receive the message.
while (true) {
message = consumer.receive();
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
System.out.println("Received message '" + textMessage.getText() + "'");
}
}
// We will be using TestMessage in our example. MessageProducer sent us a
// TextMessage
// so we must cast to it to get access to its .getText() method.
// connection.close();
}
I want to use wss protocol. This is a must for me. When I changed url with wss://host:port getting;
Could not create Transport. Reason: java.io.IOException: createTransport() method not implemented!
So I checked the alternatives. People figure this out with Stomp over WS. My first achievement is wss connection.
Any recommendation will be appreciated!
The exception you're seeing is expected because the OpenWire JMS client you're using doesn't support WebSocket connections, and it doesn't really need to. WebSocket connections are really only relevant for clients running in a limited environment like a web browser. Web browsers don't support running Java clients.
If you really want to use STOMP over WebSockets then you'll have to use a STOMP client implementation that supports WebSockets (most do).
Keep in mind that ActiveMQ is a broker. It does not supply clients for all the protocols it supports. It only provides a JMS client because it is required in order to implement JMS. STOMP, for example, is a standardized protocol and anyone can implement a client which will work with any broker implementing STOMP. There are lots of STOMP client implementations available written in many different languages for many different platforms. Any good search engine should help you find one to fit your needs.

How to set Eureka URL from code at client application startup

We need to set Eureka server URL at client application from startup code, but it seems there is no way how to do it.
We have a mechanism how to discover Eureka server on network by UDP multicast broadcasting. Server sends response back to the client with information about IP address and port where Eureka server is running. But we don't know how to set this URL in Eureka client application from code. It seems the only way how to set Eureka server URL is the property eureka.client.serviceUrl.defaultZone in application.property file.
// Server - start a new thread with UDP packet detection and reply mechanism
LocationService.listenAndReplyToEurekaClients(thisServerPort);
// Server - application start
SpringApplication.run(EurekaServerApplication.class, args);
// Client - send UDP packet and receive reply with Eureka server IP and port
Response response = LocationService.findEurekaServerAddress(5, 3, TimeUnit.SECONDS);
var hostProtocol = "http";
var eurekaUrl = new URL(
hostProtocol,
response.getEurekaAddress(),
response.getEurekaPort(),"").toString();
We would like to set this eurekaURL to the client before it starts registering to Eureka server.
In this case, we can do following things-
Extend EurekaClientConfigBean and override getEurekaServerServiceUrls method. Method returns a List of String which is nothing but list of all the URLS, of eureka instances. You need to set the URL here from your response which has IP and port.
Later create the discovery client using- DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config). (Its going to be a Bean for sure).
That should work.
You can create ApplicationInfoManager as-
ApplicationInfoManager applicationInfoManager =
initializeApplicationInfoManager(webAppInstanceConfig);
Where WebAppInstanceConfig is-
class WebAppInstanceConfig extends MyDataCenterInstanceConfig {// Override all the needed properties from MyDataCenterInstanceConfig}

Kafka SimpleConsumer cannot connect to zookeeper : Received -1 when reading from channel

I'm trying to connect to a remote kafka zookeeper (zookeeperhost:1234) via SimpleConsumer, and pulling metadata for the topics that I've specified. However, I get this error:
RunnerMain failed :java.io.EOFException: Received -1 when reading from channel, socket has likely been closed.
I ran telnet zookeeperhost 1234 and got the following:
Trying <ip addr of host>...
Connected to zookeeperhost.somedomain.com.
Escape character is '^]'.
So it looks like I am able to reach the service, there is no security/permission issue.
Here is my code:
SimpleConsumer consumer = new SimpleConsumer ("zookeeperhost", 1234, 100000, 64 * 1024, "leader_lookup");
List<String> topics = Collections.singletonList("some_event");
TopicMetadataRequest req = new TopicMetadataRequest(topics);
TopicMetadataResponse resp = consumer.send(req); //this is the line that is causing the error
List<TopicMetadata> metaData = resp.topicsMetadata();
You need to connect SimpleConsumer to a kafka leader broker (port 9092 by default) not a zookeeper. Check this link for the details how to use SimpleConsumer: https://cwiki.apache.org/confluence/display/KAFKA/0.8.0+SimpleConsumer+Example

Setting the URL for a JMS connection

The JMS Hello World example shows producers and consumers sending and consuming messages; this is how they seem to create the connection:
ConnectionFactory cf = new com.sun.messaging.ConnectionFactory();
Connection connection = cf.createConnection();
How specify the address and parameters of the remote JMS server?
I want to create an encrypted and compressed connection to an OpenMQ server that is running on another machine. Ideally I would like to use both client and server authentication.
This post seems to provide an example using JMS server address.
This is how it creates a connection. They provide the address and also username and password (admin).
String addressList = "http://127.0.0.1:8080/imqhttp/tunnel";
com.sun.messaging.TopicConnectionFactory topicConnectionFactory = new com.sun.messaging.TopicConnectionFactory();
topicConnectionFactory.setProperty(com.sun.messaging.ConnectionConfiguration.imqAddressList, addressList);
javax.jms.Topic top;
javax.jms.Connection con = topicConnectionFactory.createTopicConnection("admin", "admin");

Akka Remoting: Connection refused: no further information in "tell" method

I have the same problem you had sometime ago:
"Getting errors with remote actor deployment in Akka 2.0 RC2"
How did yousolve it? I'm using Akka 2.1.2, but I think my problem is the concept.
I create the actor:
ActorRef actorOf = system.actorOf(new Props(HelloWorld.class), "injbct");
and then in other jvm I try to lookup it up :
ActorRef actorFor = system.actorFor("akka://KSystem#127.0.0.1:2552/user/injbct");
Regards, José
I have discovered that if you are accessing a remote actor in the same machine the localhost address of 127.0.0.1 or the machine's actual IP address must be used in both the configuration of the remote actor and the actor declaration in the actor user, i.e. they cannot be mixed.
The remote actor config
remote {
transport = "akka.remote.netty.NettyRemoteTransport"
netty {
hostname = "127.0.0.1"
port = 2554
Considering the machine to have an IP address of 1.2.3.4, then
This works
val workerRouter =
context.actorFor("akka://PrimeWorkerKernel#127.0.0.1:2554/user/PrimeWorkerActor")
This does not and results in a connection refused
val workerRouter =
context.actorFor("akka://PrimeWorkerKernel#1.2.3.4:2554/user/PrimeWorkerActor")
For starters, you should read the Akka Remoting documentation. Then, make sure you have the remoting dependency in your pom file:
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-remote_2.10</artifactId>
<version>2.1.4</version>
</dependency>
Then, both sides (the calling side and the receiving side will need to have remoting config in their application.conf files similar to the example in the remoting docs:
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
transport = "akka.remote.netty.NettyRemoteTransport"
netty {
hostname = "127.0.0.1"
port = 2552
}
}
}
You'll notice that the actor ref provider has been set to the RemoteActorRefProvider as opposed to the default LocalActorRefProvider. Without this on the sending actor side, things won't work. You'll also see that netty binding info has been setup and this is really important on the receiving actor side so that ActorSystem is listening for remote connections and messages. If you follow the steps in the docs and start up your receiving actor system as ActorSystem("KSystem") then things should work for you.

Categories

Resources