I have written a sample application to write to a public and private queues that are on dev server. I don't have the message queue installed on my local machine.
I am getting error: message queuing has not been installed on this computer.
Error is on this line:
MessageQueue.Exists(queueName)
Here is the full test code, all commented and not commented private and public queues are resulting in the same error. What am i doing wrong here?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Messaging;
namespace MsmqTest
{
public partial class Form1 : Form
{
//#"DIRECT=OS:devbox01\PRIVATE$\PrivateQueueDev";
//#"DIRECT=TCP:192.168.6.102\PRIVATE$\PrivateQueueDev";
private const string QueueName = #"DIRECT=TCP:192.168.6.102\PRIVATE$\PrivateQueueDev";
//#"DIRECT=OS:devbox01\PublicQueueDev";
//#"DIRECT=TCP:192.168.6.102\PublicQueueDev";
private const string QueueNamePublic = #"DIRECT=TCP:192.168.6.102\PublicQueueDev";
public Form1()
{
InitializeComponent();
}
private void Write_Click(object sender, EventArgs e)
{
MessageQueue msgQ;
string msgText = String.Format("Message: {0}", DateTime.Now);
try
{
msgQ = GetQ(QueueNamePublic);
msgQ.Send(msgText);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
private void Read_Click(object sender, EventArgs e)
{
}
private MessageQueue GetQ(string queueName)
{
MessageQueue msgQ;
if(!MessageQueue.Exists(queueName))
{
try
{
msgQ = MessageQueue.Create(queueName);
}
catch (Exception ex)
{
throw new Exception("Error creating queue", ex);
}
}
else
{
try
{
msgQ = new MessageQueue(queueName);
}
catch (Exception ex)
{
throw new Exception("Error getting queue", ex);
}
}
return msgQ;
}
}
}
You need to install MSMQ on ALL machines which want to participate in the transmission and reception of messages. That includes sending machines such as your local machine in this instance.
The reason for this is because of the store-and-forward messaging pattern that MSMQ uses.
http://en.wikipedia.org/wiki/Store_and_forward
What is actually happening when you "send" a message to your server is:
The local queue manager writes the message to a local temporary queue.
The local queue manager connects to the remote queue manager.
The message is transmitted.
The remote queue manager writes the message to the remote queue.
Refactor out the MSMQ logic to a service and call the service from your code, passing the message. That way you only have to install MSMQ on the server.
Related
Just need to check the feasibility if we can deploy our own custom rest method into apache ignite service grid which can be accessed by clients.
Idea is to get the request into my custom rest method exposed, make the relevant changes and send back the response.
Thanks,
It's not trivial to add a method to the existing Ignite REST server but it's fairly straight-forward to have your own end-point running using the Service Grid.
This is my aproach using Ignite service proxy (don't forget disable ignite embedded http or you have to exclude some dependencies):
RESTServiceImpl.java:
public class RESTServiceImpl implements RESTService {
#IgniteInstanceResource
private Ignite ignite;
#LoggerResource
private IgniteLogger log;
private Server jettyServer;
public void init(ServiceContext ctx) {
ServletContextHandler context = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/api");
jettyServer = new Server(8888);
jettyServer.setHandler(context);
ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*");
jerseyServlet.setInitOrder(0);
// Tells the Jersey Servlet which REST service/class to load.
jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "services.rest");
}
public void execute(ServiceContext ctx) {
log.info("Starting REST Service");
try {
jettyServer.start();
} catch (Exception e) {
e.printStackTrace();
}
log.info("Starting REST Service : OK");
}
public void cancel(ServiceContext ctx) {
log.info("Stopping REST Service on node:" + ignite.cluster().localNode());
try {
jettyServer.stop();
} catch (Exception e) {
e.printStackTrace();
}
RESTController.java:
#Path("/mypath")
public class EventCaseController {
private Ignite ignite = Ignition.ignite();
private RESTService restService = ignite.services().serviceProxy(RESTService.SERVICE_NAME,
RESTService.class, false);
#GET
#Path("size")
#Produces(MediaType.APPLICATION_JSON)
public JSONObject eventCaseCacheSize() {
// some logics
}
}
Does anyone know how to open a JavaFx application via rest requests?
Scenario:
I have a Spring Boot Service that runs on every machine to make a bridge wiht my SPA(Single Page Application) and my comm ports. Thats because SPA cannot talk to the OS.
This communications are made via http requests.
Now I have a problem, I need to make a javafx application that is started via http request, when I call the firts time, it works ok, but if i close the javafx application clicking on 'x' and try to open again I'm getting the following error:
java.lang.IllegalStateException: Application launch must not be called more than once
There is a way that when I close the javafx window, it kill the JavaFx Thread, so when I call it again, it start a new Thread?
Or do I need to keep the Thread and just find a way to reopen my javafx application in the same Thread?
here is my #Controller
#RestController
#RequestMapping("v1/appfx")
public class AppfxController{
#RequestMapping("")
private void openJavaFxApp(){
try{
MyJavaFxApp.launch(MyJavaFxApp.class);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
And Here is my JavaFx:
public class MyJavaFxApp extends Application {
private final static Logger log = LoggerFactory.getLogger(MyJavaFxApp.class);
private BigDecimal left;
private String selectedOperator;
private boolean numberInputting;
#FXML
private TextField display;
public MyJavaFxApp() {
this.left = BigDecimal.ZERO;
this.selectedOperator = "";
this.numberInputting = false;
}
#Override
public void start(Stage stage) throws Exception {
stage.setTitle("MyJavaFxApp");
stage.setOnCloseRequest(x -> {
log.info("closed");
Platform.exit();
});
stage.setResizable(false);
stage.setScene(new Scene(FXMLLoader.load(getClass().getClassLoader().getResource("Test.fxml"))));
stage.show();
stage.toFront();
}
}
Thanks for any help.
I am trying to create a new queue in RabbitMQ using Spring AMQP on server startup of my web application. I am not getting the exact configuration code how to achieve it.
Below is my code snippet. Please correct the following.
#Configuration
public class RabbitMQConfiguration {
#Bean
public ConnectionFactory rabbitConnectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory("10.165.18.29");
connectionFactory.setUsername("User");
connectionFactory.setPassword("user");
return connectionFactory;
}
#Bean
public SimpleMessageListenerContainer messageListenerContainer() {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(rabbitConnectionFactory());
container.addQueueNames("create.queue");
container.setMessageListener(exampleListener());
return container;
}
#Bean
public MessageListener exampleListener() {
return new MessageListener() {
public void onMessage(Message message) {
System.out.println("received: " + message);
}
};
}
}
See the documentation.
Simply add <rabbit:queue ... /> beans and a <rabbit:admin ... /> and the admin will automatically declare the queues when the connection is first established.
we are using JBoss EAP 6.2.4 and within a stateless session bean we send JMS messages to an WMQ-queuemanager.
our code is als follows:
#Stateless
#LocalBean
public class MessageSenderBean {
private static ConnectionFactory connectionFactory;
private static InitialContext initialContext;
#EJB
IntegrationPropertyBean ipb;
Logger logger = Logger.getLogger(getClass());
/**
* Default constructor.
*/
public MessageSenderBean() {
}
#PostConstruct
public void postConstruct() {
logger.debug(" MessageSenderBeanPostConstruct called");
try {
initialContext = new InitialContext();
String connectionFactoryName = ipb.getProperty(
MessageSenderBean.class, "connectionFactory");
connectionFactory = (ConnectionFactory) initialContext
.lookup(connectionFactoryName);
} catch (NamingException e) {
logger.error("Exception occurred: " + e.toString());
logger.error(e);
}
}
public String sendMessage(String queueName, String content) {
String result = null;
Connection connection = null;
try {
connection = connectionFactory.createConnection();
} catch (JMSException e) {
logger.error("Exception occurred: " + e.toString());
logger.error(e);
}
// prüfen ob InitialContext leer
try {
if (initialContext == null)
initialContext = new InitialContext();
} catch (NamingException e) {
logger.error("Exception occurred: " + e.toString());
logger.error(e);
}
after startup of the server the bean works perfectly for the first actions but after some time without any action the bean looses the initialContext and an addtional creation fails within the new InitialContext()
Any idea why?
Thanks Joerg
Take in mind the following:
The InitialContext object is not synchronized, which means that an instance should not be accessed simultaneously by different threads.
You have declared the initialContext variable as a class member (static), therefore , at some point different threads will use it simultaneously.
A simple solution is declare the attribute as an instance member.
<!-- language: java -->
private InitialContext initialContext;
Can Any one tell me How can we use signalR with Unity For Client server communication.
Im getting error in my code.
The code is as below:
using UnityEngine;
using System.Collections;
using System;
using System.Threading;
using Microsoft.AspNet.SignalR.Client;
public class SignalR : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
public class Client
{
private readonly string _platform;
private readonly HubConnection _connection;
private readonly IHubProxy _proxy;
public event EventHandler<EventArgs> OnMessageReceived;
public Client(string platform)
{
_platform = platform;
_connection = new HubConnection("http://192.168.1.103");
_proxy = _connection.CreateHubProxy("Chat");
}
public void Connect()
{
_connection.Start();
_proxy.On("messageReceived", (string platform, string message) =>
{
if (OnMessageReceived != null)
OnMessageReceived(this, string.Format("{0}: {1}", platform, message));
});
Send("Connected");
}
public void Send(string message)
{
return _proxy.Invoke("Send", _platform, message);
}
}
This is my client side code.I have added ell’s in my assets for signalR.
The error details are as below:
Internal compiler error. See the console log for more information. output was:
Unhandled Exception: Mono.CSharp.InternalErrorException: Assets/SignalR.cs(30,24): Client.Client(string) ---> System.TypeLoadException: Could not load type 'Microsoft.AspNet.SignalR.Client.Connection' from assembly 'Microsoft.AspNet.SignalR.Client, Version=2.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at (wrapper managed-to-native) System.MonoType:GetMethodsByName (string,System.Reflection.BindingFlags,bool,System.Type)
at System.MonoType.GetMethods (BindingFlags bindingAttr) [0x00000] in :0
Thanks In Advance!!