We have a service that receive the queue name and if the queue exist push data on the queue.
I'm looking to find a way to check if the queue exist on azure in java.
So far, using IQueueClient I can onl know if the queue exist when sending data via sendAsync with return a exception.
I want to found out when the client is created or even before.
The best answer I've found so far is using the NamespaceManager.
in this fashion:
Uri uri = ServiceManagementHelper.GetServiceUri();
TokenProvider tokenProvider = ServiceManagementHelper.GetTokenProvider(uri);
NamespaceManager nm = new NamespaceManager(uri, tokenProvider);
if (!nm.QueueExists("TestQueue")) return;
source:
http://www.cloudcasts.net/devguide/Default.aspx?id=12018
https://www.pmichaels.net/2017/06/11/reading-message-azure-service-bus-queue/
However this class seem not to be part of azure-core or azure-servicebus librairy and I can seem to find which lib to add to the project to have access to those class.
However this class seem not to be part of azure-core or azure-servicebus librairy and I can seem to find which lib to add to the project to have access to those class.
You mentioned code is related to .net SDK. For Java sdk we could use the following code check if the queue exist. ManagementClient seems only available in the 2.0.0-PREVIEW version. We also could get the source code from GitHub.
String connectionString = "Endpoint=sb://xxxx.servicebus.windows.net/;SharedAccessKeyName=SharedAccessKeyName;SharedAccessKey=xxxxxxxx=";
ConnectionStringBuilder connectionStringBuilder = new ConnectionStringBuilder(connectionString);
ManagementClient client = new ManagementClient(connectionStringBuilder);
boolean isExist = client.queueExists("queueName");
System.out.println(isExist);
Test Result:
Related
I have been stuck for about the past 6 hours at this point I'm thinking the only reasonable explanations are that this is a AWS SDK bug or the error message is wrong.
I am using SESv2 class from the AWS SDK in a JAVA SpringBoot app and attempting to manage various details of my SES (Simple Email Service) account.
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sesv2.SesV2Client;
import software.amazon.awssdk.services.sesv2.model.*;
I have created an IAM user, created security credentials, set them up using multiple different methods as described here guid to credentials environment I've given full access to SES to this IAM role user. I then wrote some code and I was able to do all of the following,
Create a contact list
Delete a contact list
Create contact
Create a Topic in a contact list
Send an email
However, for some unknown reason when I go to test a function I wrote to get a list of contacts so I can test sending an email to multiple contacts I get the following 403 error message,
The request signature we calculated does not match the signature you
provided. Check your AWS Secret Access Key and signing method. Consult
the service documentation for details.
I've verified the credentials are correct. I have created a new set of credentials and made the old set inactive. No dice, all the functions listed above still work however the listContacts in the SesV2Client class still fails with the same error. As you can see below I even bypassed the env variables and just hardcoded the key and secret to pull out all the stops, still fails. In the function that fails, I've gone over and over the values im passing in they are valid and exist 100% because as I said I can make the other calls in the list above to verify the topics and contact list exists.
private List<Contact> listContactsForSiteUpdatesMailingList() {
try (SesV2Client client = SesV2Client.builder()
.region(Region.US_EAST_1)
.credentialsProvider(StaticCredentialsProvider.create(awsCreds))
.build()){
TopicFilter topicFilter = TopicFilter.builder().topicName(TOPIC_SITE_UPDATES).useDefaultIfPreferenceUnavailable(true).build();
ListContactsFilter listContactsFilter = ListContactsFilter.builder().topicFilter(topicFilter).filteredStatus(SubscriptionStatus.OPT_IN).build();
ListContactsRequest listContactsRequest = ListContactsRequest.builder()
.contactListName(CONTACT_LIST).filter(listContactsFilter).build();
ListContactsResponse listContactsResponse = client.listContacts(listContactsRequest);
return listContactsResponse.contacts();
} catch (Exception ex) {
System.out.println("The email was not sent. Error message: "
+ ex.getMessage());
return null;
}
}
Whats going on here and how can I get to the bottom of this error?
EDIT:
Looking at AWS Console Users>Access Management and then looking at the user a created I can even verify that there was "programmatic access"
An example of accessing a ContactList with no issues
EDIT 2: My SES account is currently sandboxed. I just wanted to mention the question is this possibly happening because of that? Grasping at straws here.
I was able to reproduce your issue. I created a list and added a contact. Both worked. However, when i executed listContacts, I got this error:
This looks like a bug. To address this, open a Github issue on the SDK Java Github here:
https://github.com/aws/aws-sdk-java
This is confirmed as a bug in the AWS SDK. To get around this you can use the async client like so
SesV2AsyncClient client = SesV2AsyncClient.builder()
.region(Region.US_EAST_1)
.build())
TopicFilter topicFilter = TopicFilter.builder().topicName(TOPIC_SITE_UPDATES).useDefaultIfPreferenceUnavailable(true).build();
ListContactsFilter listContactsFilter = ListContactsFilter.builder().topicFilter(topicFilter).filteredStatus(SubscriptionStatus.OPT_IN).build();
ListContactsRequest listContactsRequest = ListContactsRequest.builder()
.contactListName(CONTACT_LIST).filter(listContactsFilter).build();
CompletableFuture<ListContactsResponse> listContactsResponseCompletableFuture = client.listContacts(listContactsRequest);
ListContactsResponse listContactsResponse = listContactsResponseCompletableFuture.get();
I have tried to use WalletTemplate sub-project inside bitcoinJ lib. I have tried p2pkh sends and they work fine. But then I tried to make P2WPKH payment but it failed with the following error message
org.bitcoinj.core.RejectedTransactionException: Reject: tx
539c7f25b14b20dfad1ad66923fa59bf7531cd1ebda967e8346793fa2464f5dc for
reason 'non-mandatory-script-verify-flag (Signature must be zero for
failed CHECK(MULTI)SIG operation)' (64)
This behavior doesn't exist before commit. So I'm not sure how to handle the changes introduced since this change.
I have also create github issue to get more information but I haven't got any response yet. I have tried code outside of bitcoinj's walletTemplate in another project as follows:
NetworkParameters params = TestNet3Params.get();
Address destination = Address.fromString(params, strDest);
Coin value = Coin.parseCoin(strValue);
SendRequest request = SendRequest.to(destination, value);
SendResult result = wallet.sendCoins(request);
Any help would be appreciated. Thanks
Issue was solve on github via the latest commit 7c31dcb.
I have a system that has Windows COM interface so that external applications can connect to it and it has following details
Interface: InterfaceName
Flags: (1234) Dual OleAutomation Dispatchable
GUID: {ABCDEFG-ABCD-1234-ABCD-ABCDE1234}
I'd like to connect to this interface through Java Spring Application, it will sends a request to this interface and process the response.
I've tried to use the following code
ActiveXComponent mf = new ActiveXComponent("ApplicationName.InterfaceName");
try {
Dispatch f2 = mf.QueryInterface(" {ABCDEFG-ABCD-1234-ABCD-ABCDE1234} ");
Dispatch.put(f2, 201, new Variant("Request String"));
} catch (Exception e) {
e.printStackTrace();
}
The executable file opens but it doesn't do what I want. I want to do the following.
How do I make sure, my interface has bee registered, I can see it
under
Computer\HKEY_CLASSES_ROOT\ApplicationName.InterfaceName
Using ActiveXComponent opens the instance of application, which is not required. Application is already running.
call the interface with dispid.
Retreive the response from the call/put/invoke ( which suits best
for my requiremet ? ) and process the response.
I'm working first time with JAVA-COM_Interface and don't have much experience with it also I could find very few examples on the internet for it and I tried to convert the example I found for my project, also I am not sure the approach I am taking to call the interface is correct or not I would be glad if you can give a hand!
I have resolved this using JACOB lib.
1) Download JACOB folder from here.
2) Check your application is working & has details under
Computer\HKEY_CLASSES_ROOT\ApplicationName.InterfaceName
3) Make sure ApplicationName.dll file is registered. If not use this link for more info
regsvr32
4) Use this Java Code to send data to COM Interface with below simple code.
Dispatch dispatch = new Dispatch("Application.InterfaceName");
Variant response = Dispatch.call(dispatch, <DISPID>, message);
syso(response.getString()); // to print the response
Hope this helps.
So I have a java program running within an Amazon EC2 instance. Is there a way to programatically get its own tags? I have tried instantiating a new AmazonEC2Client to us the describeTags() function but it only gives me null. Any help would be appreciated thank you.
Edit: To make things clearer, the instances are going to be unmanned worker machines spun up to solely do some computations
This should help you get started...
String instanceId = EC2MetadataUtils.getInstanceId();
AmazonEC2 client = AmazonEC2ClientBuilder.standard()
.withCredentials(new DefaultAWSCredentialsProviderChain())
.build();
DescribeTagsRequest req = new DescribeTagsRequest()
.withFilters(new Filter("resource-id", Collections.singletonList(instanceId)));
DescribeTagsResult describeTagsResult = client.describeTags(req);
List<TagDescription> tags = describeTagsResult.getTags()
You should be able to get the current instance id by sending a request to: http://169.254.169.254/latest/meta-data/instance-id. This only works within ec2. With this you can access quite a bit of information about the instance. However, tags do not appear to be included.
You should be able to take the instance id along with the correct authentication to get the instance tags. If you are going to run this on an instance, you may want to provide an IAM user with limited access instead of a user which has access to everything in case the instance is compromised.
While using user-data may be the simplest solution, the OP was asking specifically about the tagging, and unfortunately amazon hasn't made this as easy as it could be. However, It can be done. You want to use a combination of 2 amazon services.
First you need to retrieve the Instance ID. This can be achieved by hitting the URL from within your instance:
http://169.254.169.254/latest/meta-data/instance-id
Once you have the resource ID, you'll want to use Amazon's EC2 API to access the tags. Since you said you're using Java, I would suggest the Using the AWS SDK amazon makes available. Within this SDK you'll find a method called describeTags (documentation). You can use a Resource ID as one of the filters to get the specific tags to your instance. Supported filters are
tag key
resource-id
resource-type
I suggest doing this retrieval at boot using something like cloud-init and caching the tags on your server for use later if necessary.
How do i start and stop an amazon EC2 instance programmatically using aws-sdk in java?
Any helps are greatly appreciated as I have spent a day while trying to sort this out.
I've recently implemented this functionality within the Bamboo AWS Plugin; it's Open Source and the code is available on Bitbucket, you can find a complete example how to start/stop/reboot an instance within EC2Task.java (should be a separate class actually, alas ...).
Fortunately this is not complicated at all, for example, an instance can be started like so:
private String startInstance(final String instanceId, AmazonEC2 ec2, final BuildLogger buildLogger)
throws AmazonServiceException, AmazonClientException, InterruptedException
{
StartInstancesRequest startRequest = new StartInstancesRequest().withInstanceIds(instanceId);
StartInstancesResult startResult = ec2.startInstances(startRequest);
List<InstanceStateChange> stateChangeList = startResult.getStartingInstances();
buildLogger.addBuildLogEntry("Starting instance '" + instanceId + "':");
// Wait for the instance to be started
return waitForTransitionCompletion(stateChangeList, "running", ec2, instanceId, buildLogger); }
BuildLogger is Bamboo specific and waitForTransitionCompletion() is an implementation specific helper to report back on the process/result. The AmazonEC2 ec2 parameter passes the reference to an AmazonEC2Client object by means of the AmazonEC2 interface, which defines all relevant methods (amongst many others), specifically:
StartInstances()
StopInstances()
RebootInstances()
If you have already used AWS API, it's simple call on AmazonEC2Client object. Use the following methods
Start Instance
Stop Instance
Also, you might be knowing the start/stop mechanism works only for the images with root device backed by EBS.