I would like to be able to create some directories after Mule has started, but before it starts any other services.
I started looking into notifications but I'm not sure if that is the right place to do it. I will need access to the spring beans so it would have to be after spring init, but before any of the connectors and other processes kick off.
http://www.mulesource.org/display/MULE2USER/Mule+Server+Notifications
Thanks.
The mule lifecycle has several interfaces available that you could use to accomplish this.
http://www.mulesource.org/docs/site/2.2.1/apidocs/org/mule/api/lifecycle/Startable.html
.../Initialisable.html
Essentially, from what I understand, if you want something to happen when your mule instance starts you would implement startable. If you want something to happen when a specific mule component is initialized, then you would implement initialisable.
Also see http://blogs.mulesoft.org/start-me-oh-so-gently/
A really neat way of doing this is to create your own Custom Agent by implementing UMOAgent.
<!-- Enable Agents for Mule -->
<agents>
<!-- The MyAgent provides a convenient place to perform one off actions at startup/shutdown -->
<agent name="MyAgent" className="com.xxx.base.util.MyAgent" />
...
Agents have a start and Stop method which gets called by Mule, your implementing class can then add in any code you want.
See link for more info
http://www.mulesoft.org/documentation/display/MULE2USER/Mule+Agents
Related
I'm creating a new application in Zend Framework 3 and i have a question about a design pattern
Without entering in much details this application will have several Services, as in, will be connecting to external APIs and even in multiple databases, the workflow is also very complex, a single will action can have multiple flows depending on several external information (wich user logged in, configs, etc).
I know about dependency injections and Zend Framework 3 Service Manager, however i am worried about instanciating sereval services when the flow will actually use only a few of them in certain cases, also we will have services depending on other services aswell, for this, i was thinking about using singletons.
Is singleton really a solution here? I was looking a way to user singletons in Zend Framework 3 and haven't figured out a easy way since i can't find a way to user the Service Manager inside a service, as I can't retrive the instance of the Service Manager outside of the Factory system.
What is an easy way to implement singletons in Zend Framework 3?
Why use singletons?
You don't need to worry about too many services in your service manager since they are started only when you get them from the service manager.
Also don't use the service manager inside another class except a factory. In ZF3 it's removed from the controllers for a reason. One of them is testability. If all services are inject with a factory, you can easily write tests. Also if you read your code next year, you can easily see what dependencies are needed inside a class.
If you find there are too many services being injected inside a class which are not always needed you can:
Use the ProxyManager. This lazy loads a service but doesn't start it until a method is called.
Split the service: Move some parts from a service into a new service. e.g. You don't need to place everything in an UserService. You can also have an UserRegisterService, UserEmailService, UserAuthService and UserNotificationsService.
In stead of ZF3, you can also think about zend-expressive. Without getting into too much detail, it is a lightweight middleware framework. You can use middleware to detect what is needed for a request and route to the required action to process the request. Something like this can probably also done in ZF3 but maybe someone else can explain how to do it there.
when I use a #RepositoryEventHandler then its methods are only invoked when the call into the repository comes in via HTTP.
Any reason why? OK, it is called Spring Data REST, but wouldn't it be VERY useful to invoke the handler too, when I call my Repo directly, not via HTTP?
Any way to invoke the handler when called directly (some magic AOP-stuff)?
Thank you
The reason for that is that the different persistence mechanisms covered by the different Spring Data modules already ship with event mechanisms. Depending on the one you use you now get a different mechanism to use.
Unfortunately this can't be unified as e.g. with JPA not all persistence operations need to go through the repository in the first place, as JPA automatically flushes all changes that were made to an attached instance on EntityManager flush. In this case even AOP on the repository instance doesn't help.
So you're basically left with two choices:
The events exposed by Spring Data REST for all repositories (as we basically don't make use of the automatic change tracking in JPA).
The store specific event mechanisms that will make sure that the persistence mechanism exposes events as documented.
I don't know if the solution I put below from other stackoverflow questions would seen as acceptable by #Olivier-drotbohm, but from:
SpringDataRest #RepositoryEventHandler not running when Controller is added
and
#RepositoryEventHandler events stop with #RepositoryRestController
you could inject/autowire the "ApplicationEventPublisher" and fire the BeforeCreateEvent/AfterCreateEvent manually to trigger the RepositoryEventHandler.
This is not a perfect solution, but I hope it is good enough for you (and we tested it: it works).
I have just completed my first API in Apigility. Right now it is basically a gateway to a database, storing and retrieving multi-page documents uploaded through an app.
Now I want to run some processing on the documents, e.g. process them through a 3rd party API or modify the image quality etc., and return them to the app users.
Where (in which class) do I generally put such logic? My first reflex would be to implement such logic in the Resource-Classes. However I feel that they will become quite messy, obstructing a clear view on the API's interface in the code and creating a dependency on a foreign API. Also, I feel limited because each method corresponds to an API call.
What if there is a certain processing/computing time? Meaning I cannot direct respond the result through a GET request. I thought about running an asynchronous process and send a push notification to the app, once the processing is complete. But again, where in the could would I ideally implement such processing logic?
I would be very happy to receive some architectural advice from someone who is more seasoned in developing APIs. Thank you.
You are able to use the zf-rest resource events to connect listeners with your additional custom logic without polluting your resources.
These events are fired in the RestController class (for example a post.create event here on line 382).
When you use Apigility-Doctrine module you can also use the events triggered in the DoctrineResource class (for example the DoctrineResourceEvent::EVENT_CREATE_POST event here on line 361) to connect your listeners.
You can use a queueing service like ZendQueue or something (a third party module) built on top of ZendQueue for managing that. You can find different ZF2 queueing systems/modules using Google.
By injecting the queueing service into your listener you can simply push your jobs directly into your queue.
We have defined spring beans in Mule-config.xml. Certain public methods in this bean class needs to be periodically executed. We attempted to used spring quartz and spring task scheduler (adding beans in mule-config.xml)- but method is not executing in a schedule way - it is not triggered. Even using annotation (scheduled) does not work. Any work around for this? Any issue with spring scheduler with mule? Kindly help.
Thanks
If you want to use the Schedule annotation, take a look at this recent answer on the subject for a workaround.
Otherwise, Spring Quartz should work fine too. What have you tried? Share your config and specify the Mule version you're using. I'll review my answer accordingly.
I am new to Mule and hoping to avoid going in the completely wrong direction. I would like to create a component, which other devs can add to their Components lists in Mule Studio (to be dropped into their flows).
I see that I can create a Java class that implements callable, which can be added to a Flow by using a Java component and setting its "Class Name" to the one I created. Is there a good way that I can use this to package as a component that can be plugged in to Mule Studio? Or is Mule Devkit the best option for this?
Mule DevKit is the very best option for this. Other alternatives imply messing with Eclipse-related code. You don't want that, go DevKit: http://www.mulesoft.org/documentation/display/current/Mule+DevKit