Can txAMQP unbind in RabbitMQ? - message-queue

I want to remove bindings in RabbitMQ without deleting the bound queue. I am using txAMQP with the 0.8 AMQP spec; it seems to be the only version that RabbitMQ supports but it has no unbind method.
Oddly enough, a perusal through the source code suggests that RabbitMQ supports unbind, which leaves me rather confused.
Can I unbind with this combination of client and server? If so, how?

As you've noticed, RabbitMQ has for a few versions now supported an extension Queue.Unbind method, with definition lifted from the 0-9 specification, but not all AMQP client libraries have been extended in the same way.
To get this to work with txAMQP, you will need to take the XML definitions of the Queue.Unbind and Queue.UnbindOk methods from the 0-9 spec, paste them into the 0-8 spec file txAMQP uses, and restart your application. It should now have a Queue.Unbind method available, if I've properly understood how txAMQP works.
Here are the relevant XML stanzas, from the BSD-licensed 0-9-1 spec:
<method name="unbind" synchronous="1" index="50">
<chassis name="server" implement="MUST"/>
<response name="unbind-ok"/>
<field name="reserved-1" type="short" reserved="1"/>
<field name="queue" domain="queue-name"/>
<field name="exchange" domain="exchange-name"/>
<field name="routing-key" domain="shortstr"/>
<field name="arguments" domain="table"/>
</method>
<method name="unbind-ok" synchronous="1" index="51">
<chassis name="client" implement="MUST"/>
</method>

Related

PhpStorm unable to resolve symbol 'doctrine.orm.entity_manager'

When I open the services.xml in PhpStorm with Symfony Plugin enabled, it's able to resolve all the services, I can Ctrl+Click and go the Service Definition , except doctrine.orm.entity_manager.
It says unable to resolve symbol 'doctrine.orm.entity_manager'
Here is the services.xml file
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="example_manager" class="Vendor\XysBundle\Manager\ExampleManager">
<argument type="service" id="doctrine.orm.entity_manager" />
</service>
</services>
</container>
PhpStorm Details:
PhpStorm 2016.3.1
Build #PS-163.9735.1, built on December 6, 2016
JRE: 1.8.0_112-release-408-b2 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
appDevDebugProjectContainer.xml file exists in the app/cache directory .
How can I get get this working ?
I have the same issue. If you open up the vendor\doctrine\doctrine-bundle\Resources\config\orm.xml file where doctrine services are defined, you can see, there is no service with the id "doctrine.orm.entity_manager" but only "doctrine.orm.entity_manager.abstract"
The definition looks like:
<service id="doctrine.orm.entity_manager.abstract" class="%doctrine.orm.entity_manager.class%" abstract="true" />
As you can see the abstract attribute is set to true. This means this service can serve as a parent of other services, and when you define child services with this abstract parent you don't have to define the method calls or the parameters injected into the constructor for example, instead these definitions will be inherited from the parent.
If you investigate a bit deeper you will find that %doctrine.orm.entity_manager.class% is defined in the same file as a parameter that actually references to the Doctrine Entity Manager:
<parameter key="doctrine.orm.entity_manager.class">Doctrine\ORM\EntityManager</parameter>
So I guess we should use doctrine.orm.entity_manager.abstract, however doctrine.orm.entity_manager is recognised as well, although I don't know how.
For further explanation of abstract service definitions have a look at this Symfony doc page: https://symfony.com/doc/current/service_container/parent_services.html

checkstyle - prohibit initializing object of type

suppose I have an external library with a class called Foo. I can't change Foo to have a private constructor, but I have a FooFactory class that I wrote.
So I have FooFactory.getAFoo() but I want checkstyle to catch any new Foo() in the rest of my code, to force using the factory.
I have this:
<module name="IllegalTokenText">
<property name="tokens" value="LITERAL_NEW"/>
<property name="format" value="Foo"/>
</module>
but this doesn't seem to detect a new Foo().
I could use a regex but this is much cleaner.
I had a similar problem with preventing extending a class:
<module name="IllegalTokenText">
<property name="tokens" value="EXTENDS_CLAUSE"/>
<property name="format" value="AndroidTestCase"/>
</module>
Neither of these checkstyle module seem to do anything at all.
What am I doing wrong?
IllegalTokenText checks for illegal text on the token itself, not on subsequent IDENT tokens or some such. So that is why it seems to do nothing in your case.
In your case, you may want to try using the SevNTU Checkstyle extension, which offers a check called ForbidInstantiation which might solve your problem. They have no documentation that I am aware of, so I am linking the source code with Javadoc. When you use SevNTU Checkstyle, be sure to use the right versions of regular Checkstyle and SevNTU Checkstyle, because not all combinations are compatible (overview).
If that does not help, you will have to roll your own.

Mule Functional Tests - totally confused

We have a Mule application with 6 or seven flows with around 5 components per flow.
Here is the setup.
We send JMS requests to an ActiveMQ Queue. Mule listens to that. Based on content of the message we forward that to corresponding flows.
<flow name="MyAPPAutomationFlow" doc:name="MyAPPAutomationFlow">
<composite-source>
<jms:inbound-endpoint queue="MyAPPOrderQ" connector-ref="Active_MQ_1" doc:name="AMQ1 Inbound Endpoint"/>
<jms:inbound-endpoint queue="MyAPPOrderQ" connector-ref="Active_MQ_2" doc:name="AMQ2 Inbound Endpoint"/>
</composite-source>
<choice doc:name="Choice">
<when expression="payload.getProcessOrder().getOrderType().toString().equals("ANC")" evaluator="groovy">
<processor-chain>
<flow-ref name="ProcessOneFLow" doc:name="Go to ProcessOneFLow"/>
</processor-chain>
</when>
<when....
...........
</choice>
</flow>
<flow name="ProcessOneFLow" doc:name="ProcessOneFLow">
<vm:inbound-endpoint exchange-pattern="one-way" path="ProcessOneFLow" responseTimeout="10000" mimeType="text/xml" doc:name="New Process Order"/>
<component doc:name="Create A">
<spring-object bean="createA"/>
</component>
<component doc:name="Create B">
<spring-object bean="createB"/>
</component>
<component doc:name="Create C">
<spring-object bean="createC"/>
</component>
<component doc:name="Create D">
<spring-object bean="createD"/>
</component>
</flow>
<spring:beans>
<spring:import resource="classpath:spring/service.xml"/>
<spring:bean id="createA" name="createA" class="my.app.components.CreateAService"/>
<spring:bean id="createB" name="createB" class="my.app.components.CreateBService"/>
<spring:bean id="createC" name="createC" class="my.app.components.CreateCService"/>
<spring:bean id="createD" name="createD" class="my.app.components.CreateDService"/>
......
......
</spring:beans>
Now I am not sure how I can write Functional tests with them.
I went through the Functional Testing documentation in Mule website but there they have very simple tests.
Is Functional Testing not supposed to make actual backend updates using DAO or Service layers or is it just an extension of Unit tests where you mock up service layer?
I was of the idea - it can take in a request and use the inmemory Mule server to pass the request-response from one component to another in a flow.
Also kindly note there is no Outbound endpoint for any of our flows as they are mostly Fire and Forget type flows and status updates are managed by the DB updates the components do.
Also why do I need to create separate mule config xml files for tests? If I am not testing the flow xml that will actually be deployed on Live what's the point of this testing? I f I am creating separate xml configs just for tests that somewhat defeats the purpose to me...
Can some expert kindly elucidate a bit more and point to example tests similar to the ones we are using.
PS: the components inside Mule are dependent on external systems like webservices, databases etc. For Functional tests do we need to have those running or are we supposed to mock out those services/Db Access?
Functional testing your Mule application is no different from testing any application that relies on external resources, like databases or JMS brokers, so you need to use the same techniques you would do with a standard application.
Usually this means stubbing the resources out with in-memory implementations, like HSQLDB for databases or a transient ActiveMQ in-memory broker for JMS. For a Mule application, this implies modularizing your configuration so "live" transports are defined in a separate file, which you replace with one that contains the in-memory variants at testing time.
To validate Mule had the correct interaction with the resource, you can either read the resource directly using its Java client (for example JDBC or JMS), which is good if you want to ensure that purely non-Mule clients have no issue reading what Mule has dispatched, or use the MuleClient to read from these resources or create flows that consume these resources and pass messages to the <test:component>.
FYI These different techniques are explained and demonstrated in chapter 12 of Mule in Action, second edition.
https://blog.codecentric.de/en/2015/01/mule-esb-testing-part-13-unit-functional-testing/
https://developer.mulesoft.com/docs/display/current/Functional+Testing
Please refer this links
As you can see, it's an ordinary JUnit test extending FunctionalMunitSuite class.
There are two thing we need to do in our test:
Prepare MuleEvent object as an input to our flow. We can do that by using provided testEvent(Object payload) method.
Execute runFlow(String flowName, MuleEvent event) method specifying flow name to test against and event we just created in the first step.

Help with Castle Windsor XML configuration

I have the following three components defined in the Caste-Windsor XML configuration for my application:
<component id="StringFactory"
service="IStringFactory, MyApp"
type="DefaultStringFactory, MyApp"
lifestyle="singleton"
/>
<component id="TheString"
type="System.String"
factoryId="StringFactory"
factoryCreate="CreateString"
>
<parameters>
<name>SomeString</name>
</parameters>
</component>
<component id="TheTarget"
service="ITarget, MyApp"
type="TheTarget, MyApp"
lifestyle="transient"
>
<parameters>
<aString>${TheString}</aString>
</parameters>
</component>
And the following facility defined:
<facility id="factory.support"
type="Castle.Facilities.FactorySupport.FactorySupportFacility, Castle.MicroKernel"
/>
When I run the application and set a breakpoint in the constructor of the TheObject class, the value passed in as the aString parameter is "${TheString}" when I expect it to resolve to the value of the component with that name.
Also, I have a breakpoint in the StringFactory constructor and CreateString method, neither of which are hit. I know the configuration is being used as other components are resolving correctly.
What am I missing or doing wrong here?
UPDATE
In light of the huge tangient this topic has taken, I've refactored the code above to remove anything to do with connection strings. The original intent of this post was about injecting a property with the value returned from a method on another object. Somehow that point was lost in a discussion about why I'm using XML versus code-based configuration and if this is a good way to inject a connection string.
The above approach is far from an original idea and it was pulled from several other discussions on this topic and our requirements are what they are. I'd like help understanding why the configuration as it is in place (whether the right approach or not) isn't working as expected.
I did verify that the first two components are being instantiated correctly. When I call Container.Resolve("TheString"), I get the correct value back. For whatever reason, The parameter syntax is not working correctly.
Any ideas?
While not a definitive solution to what I need to do in my application, I believe I've figured out what is wrong with the code. Or at least I've found a way to make it work which hints at the original problem.
I replaced the String type for TheString with a custom class. That's it. Once I did that, everything worked fine.
My guess is that it has something to do with the fact that I was trying to use a ValueType (primitive) as a component. I guess Castle doesn't support it.
So, knowing that's the case, I can now move on to figuring out if this approach is really going to work or if we need to change direction.
UPDATE
For the sake of completeness, I thought I'd go ahead and explain what I did to solve my problem AND satisfy my requirements.
As before, I have access to my configuration settings through an IConfigurationService defined as:
<component id="ConfigurationService"
service="MyApp.IConfigurationService, MyApp"
type="MyApp.RuntimeConfigurationService, MyApp"
lifestyle="singleton"
/>
This is automatically injected into my (new) IConnectionFactory which is responsible for generating IDbConnection objects based on the connection strings defined in the application's configuration file. The factory is declared as:
<component id="ConnectionFactory"
service="MyApp.Factories.IConnectionFactory, MyApp"
type="MyApp.Factories.DefaultConnectionFactory, MyApp"
lifestyle="singleton"
/>
In order to resolve what connection is used by my repository, I declare each connection as a component using the ConnectionFactory to create each instance:
<component id="MyDbConnection"
type="System.Data.IDbConnection,
System.Data, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089"
factoryId="ConnectionFactory"
factoryCreate="CreateConnection"
lifestyle="transient"
>
<parameters>
<connectionStringName>MyDB</connectionStringName>
</parameters>
</component>
Notice the fully described reference to System.Data. I found this is necessary whenever referencing assemblies in the GAC.
Finally, my repository is defined as:
<component id="MyRepository"
service="MyApp.Repositories.IMyRepository, MyApp"
type="MyApp.Sql.SqlMyRepository, MyApp.Sql"
lifestyle="transient"
>
<parameters>
<connection>${MyDbConnection}</connection>
</parameters>
</component>
Now everything resolves correctly and I don't have ANY hard-coded strings compiled into my code. No connection string names, app setting keys or whatever. The app is completely reconfigurable from the XML files which is a requirement I must satisfy. Plus, other devs that will be working with the solution can manage the actual connection strings in the way they are used to. Win-win.
Hope this helps anyone else that runs into a similar scenario.
You don't really need XML registrations here, since you probably don't need to swap components or change the method used without recompiling. Writing a configurable app does not imply having to use XML registrations.
The problem with this particular XML registration you posted is that the connection string is a parameter, but it's treated like a service.
Doing this with code registrations is much easier, e.g.:
var container = new WindsorContainer();
container.Register(Component.For<IConfigurationService>().ImplementedBy<RuntimeConfigurationService>());
container.Register(Component.For<ITheRepository>().ImplementedBy<TheRepository>()
.LifeStyle.Transient
.DynamicParameters((k, d) => {
var cfg = k.Resolve<IConfigurationService>();
d["connectionString"] = cfg.GetConnectionString();
k.ReleaseComponent(cfg);
}));
Or if you don't want to depend on IConfigurationService, you could do something like:
container.Register(Component.For<ITheRepository>().ImplementedBy<TheRepository>()
.LifeStyle.Transient
.DependsOn(Property.ForKey("connectionString")
.Is(ConfigurationManager.ConnectionStrings[ConfigurationManager.AppSettings["connName"]].ConnectionString))

How can I add Snapshot and test variations to my ivy.xml

I'm using ant+ivy+nexus to build and publish my java OSGi projects (just good old jars if you're unfamiliar with OSGi). After the usual mind-melting period one has when engaging with new tech I've got a mostly functional system. But, I now have two dimensions of artifact variation: snapshot/release and main/test.
The main/test dimension speaks for itself really. The snapshot/release is essential for publishing into nexus in a maven-friendly way. (Extremely useful for integration with open-source OSGi runtimes). So, I have the following artifacts on a per-project basis, and I have many many projects:
project-revision.xml (bp)
project-test-revision.xml (b)
project-revision-SNAPSHOT.xml (bp)
project-test-revision-SNAPSHOT.xml (b)
b = successfully building
p = successfully publishing
(I haven't yet got the test stuff publishing correctly)
It's taken me a while to get that far without duplicating code everywhere in my build scripts, but I've managed it... with one big caveat. For the SNAPSHOT branch I append "-SNAPSHOT" to all revisions. In ant I manage to achieve this programatically, but for ivy I'm using a duplicated ivy.xml; ivy-SNAPSHOT.xml. This has
<info ... revision="x.x-SNAPSHOT">
Notice the -SNAPSHOT. Without this I could never get my
<ivy:deliver>
<ivy:resolve>
<ivy:publish>
chain of commands to correctly publish artifact and maven pom. (Remember I have a requirement to make this maven friendly... I'll be damned if I actually end up using maven to build it mind!)
Now I'm stuck introducing the test/main dimension. I'm ideally looking to publish
project-test-revision(-SNAPSHOT).jar
(Note the optional snapshot). I really don't want to do this by specifying
<info ... module="project-test" ... >
as opposed to <info ... module="project" ... > in yet another ivy file. If I went this route (like I've already started) then I simply end up with loads of ivy-Option1-Option2...-OptionN.xml files. With each new two-value variation doubling the number of build and ivy files. That's crap. There's got to be a better way. I just can't find it.
If you have managed to successfully get ivy publishing artifacts with embellished names from one ivy file, would you mind posting the configuration snippets that achieve this? Would be extremely useful. (Don't forget maven won't know about configurations so I need to get the variations into the filename and pom).
Many thanks
Alastair
Ok, update: I've now got the artifact publishing. I struggled a little while I had the test conf extending the default conf. I'd get a complaint during publishing that the default configuration artifacts weren't present... something I don't care about while only publishing the test case. By making them independent but overlapping I get back fine-grain control of what to publish.
BUT!!!!! There's no viable test pom - that's NOT publishing yet. Well, actually it does publish, but it contains data for the non-test case. So this is still not maven friendly. If anyone has suggestions on this that'd be great.
either way, the code I'm now using, in case it helps you too:
ivy.xml:
<info
organisation="MY_ORGANISATION"
module="MY_PROJECT"
status="integration"
revision="1.0-SNAPSHOT">
</info>
<configurations>
<conf name="default" description="Default compilation configuration; main classes only" visibility="public"/>
<conf name="test" description="Test-inclusive compilation configuration. Don't forget to also add Default compilation configuration where needed. This does not extend default conf" visibility="public"/>
</configurations>
<publications>
<artifact name="MY_PROJECT type="jar" ext="jar" conf="default"/>
<artifact name="MY_PROJECT type="pom" ext="pom" conf="default"/>
<artifact name="MY_PROJECT-test" type="jar" ext="jar" conf="test"/>
<artifact name="MY_PROJECT-test" type="pom" ext="pom" conf="test"/>
</publications>
<dependencies>
<dependency org="MY_ORGANISATION" name="ANOTHER_PROJECT" rev="1.0-SNAPSHOT" transitive="true" conf="*"/>
<dependency org="junit" name="junit" rev="[4,)" transitive="true" conf="test->*"/>
</dependencies>
build.xml:
<property name="project.generated.ivy.file" value="SNAPSHOT_OR_RELEASE_IVY_XML_FILE" />
<property name="ivy.publish.status" value="RELEASE_OR_INTEGRATION" />
<property name="project.qualifier" value="-SNAPSHOT_OR_EMPTY" />
<property name="ivy.configuration" value="DEFAULT_OR_TEST" />
<target name="publish" depends="init-publish">
<ivy:deliver
deliverpattern="${project.generated.ivy.file}"
organisation="${project.organisation}"
module="${project.artifact}"
status="${ivy.publish.status}"
revision="${project.revision}${project.qualifier}"
pubrevision="${project.revision}${project.qualifier}"
conf="${ivy.configuration}"
/>
<ivy:resolve conf="${ivy.configuration}" />
<ivy:makepom
ivyfile="${project.generated.ivy.file}"
pomfile="${project.pom.file}"
/>
<ivy:publish
resolver="${ivy.omnicache.publisher}"
module="${project.artifact}"
organisation="${project.organisation}"
revision="${project.revision}${project.qualifier}"
pubrevision="${project.revision}${project.qualifier}"
pubdate="now"
overwrite="true"
publishivy="true"
status="${ivy.publish.status}"
artifactspattern="${project.artifact.dir}/[artifact]-[revision](-[classifier]).[ext]"
conf="${ivy.configuration}"
/>
</target>